{"cells":[{"cell_type":"markdown","metadata":{"id":"3CA803EF0A7543C88A542441D9972FED","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 这十套练习，教你如何用Pandas做数据分析\n","\n","\n","```Pandas```是入门```Python```做数据分析所必须要掌握的一个库。建议完成[Pandas基础命令速查表](https://www.kesci.com/apps/home/project/59e389b54663f7655c48f518) 教程学习的之后，对本教程代码进行调试学习。"]},{"cell_type":"markdown","metadata":{"id":"812008E3575B41FE9535D183CF7713F2","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习题索引\n","点击习题编号即可跳转至习题内容。\n","\n","|习题编号|内容|相应数据集|\n","|:---- |:-----|:------|\n","|[练习1 - 开始了解你的数据](#练习1-开始了解你的数据) |探索Chipotle快餐数据|chipotle.tsv|\n","|[练习2 - 数据过滤与排序](#练习2-数据过滤与排序) | 探索2012欧洲杯数据|Euro2012_stats.csv|\n","|[练习3 - 数据分组](#练习3-数据分组) |探索酒类消费数据|drinks.csv|\n","|[练习4 -Apply函数](#练习4-Apply函数)|探索1960 - 2014 美国犯罪数据|US_Crime_Rates_1960_2014.csv|\n","|[练习5 - 合并](#练习5-合并)|探索虚拟姓名数据|练习中手动内置的数据|\n","|[练习6 - 统计](#练习6-统计)|探索风速数据|wind.data|\n","|[练习7 - 可视化](#练习7-可视化)|探索泰坦尼克灾难数据|train.csv|\n","|[练习8 - 创建数据框](#练习8-创建数据框)|探索Pokemon数据|练习中手动内置的数据|\n","|[练习9 - 时间序列](#练习9-时间序列)|探索Apple公司股价数据|Apple_stock.csv|\n","|[练习10 - 删除数据](#练习10-删除数据) |探索Iris纸鸢花数据|iris.csv|\n"]},{"cell_type":"markdown","metadata":{"id":"65DDD864CD7C4B0E89601D1A42EA3DE4","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 对应的数据集文件路径查看"]},{"cell_type":"code","execution_count":3,"metadata":{"collapsed":false,"id":"6FCA8E16DE4A49A890B2D08F1DFBC83D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["Apple_stock.csv               cars.csv      iris.csv              wechart.csv\r\n","Euro2012_stats.csv            chipotle.tsv  second_cars_info.csv  wind.data\r\n","US_Crime_Rates_1960_2014.csv  drinks.csv    train.csv\r\n"]}],"source":["ls /home/mw/input/pandas_exercise/pandas_exercise/exercise_data/"]},{"cell_type":"markdown","metadata":{"id":"15AE1A1334184C649F148EF974EA9ACA","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习1-开始了解你的数据\n","## 探索Chipotle快餐数据\n","![image description](https://cdn.kesci.com/images/lab_upload/1508342529498_40648.jpeg)"]},{"cell_type":"markdown","metadata":{"id":"DB1986733FFC480081DC3BAADFFC77C3","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"5D459F7146964C0481088B6FA4A23D4F","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":7,"metadata":{"collapsed":false,"id":"C75CEAB06B5844DC83E4A424C8BACBBE","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd"]},{"cell_type":"markdown","metadata":{"id":"D0E71B00CB954BCC8FB77990D8A180AA","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 从如下地址导入数据集"]},{"cell_type":"code","execution_count":5,"metadata":{"collapsed":false,"id":"FAE7F6593502441C8CB6465B290F66DC","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path1 = \"../input/pandas_exercise/pandas_exercise/exercise_data/chipotle.tsv\"    # chipotle.tsv"]},{"cell_type":"markdown","metadata":{"id":"50182838108846F5872B34720715C4FF","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将数据集存入一个名为chipo的数据框内"]},{"cell_type":"code","execution_count":8,"metadata":{"collapsed":false,"id":"DC17C7E623374BA285684FE3B771AD41","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","chipo = pd.read_csv(path1, sep = '\\t')"]},{"cell_type":"markdown","metadata":{"id":"05D6924392E4448980086187F6CEB8E0","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 查看前10行内容"]},{"cell_type":"code","execution_count":9,"metadata":{"collapsed":false,"id":"4D527E9B55F543C691192F42AF23343A","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>order_id</th>\n","      <th>quantity</th>\n","      <th>item_name</th>\n","      <th>choice_description</th>\n","      <th>item_price</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Chips and Fresh Tomato Salsa</td>\n","      <td>NaN</td>\n","      <td>$2.39</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Izze</td>\n","      <td>[Clementine]</td>\n","      <td>$3.39</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Nantucket Nectar</td>\n","      <td>[Apple]</td>\n","      <td>$3.39</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Chips and Tomatillo-Green Chili Salsa</td>\n","      <td>NaN</td>\n","      <td>$2.39</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>2</td>\n","      <td>2</td>\n","      <td>Chicken Bowl</td>\n","      <td>[Tomatillo-Red Chili Salsa (Hot), [Black Beans...</td>\n","      <td>$16.98</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>3</td>\n","      <td>1</td>\n","      <td>Chicken Bowl</td>\n","      <td>[Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou...</td>\n","      <td>$10.98</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>3</td>\n","      <td>1</td>\n","      <td>Side of Chips</td>\n","      <td>NaN</td>\n","      <td>$1.69</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>4</td>\n","      <td>1</td>\n","      <td>Steak Burrito</td>\n","      <td>[Tomatillo Red Chili Salsa, [Fajita Vegetables...</td>\n","      <td>$11.75</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>4</td>\n","      <td>1</td>\n","      <td>Steak Soft Tacos</td>\n","      <td>[Tomatillo Green Chili Salsa, [Pinto Beans, Ch...</td>\n","      <td>$9.25</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>5</td>\n","      <td>1</td>\n","      <td>Steak Burrito</td>\n","      <td>[Fresh Tomato Salsa, [Rice, Black Beans, Pinto...</td>\n","      <td>$9.25</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   order_id  quantity                              item_name  \\\n","0         1         1           Chips and Fresh Tomato Salsa   \n","1         1         1                                   Izze   \n","2         1         1                       Nantucket Nectar   \n","3         1         1  Chips and Tomatillo-Green Chili Salsa   \n","4         2         2                           Chicken Bowl   \n","5         3         1                           Chicken Bowl   \n","6         3         1                          Side of Chips   \n","7         4         1                          Steak Burrito   \n","8         4         1                       Steak Soft Tacos   \n","9         5         1                          Steak Burrito   \n","\n","                                  choice_description item_price  \n","0                                                NaN     $2.39   \n","1                                       [Clementine]     $3.39   \n","2                                            [Apple]     $3.39   \n","3                                                NaN     $2.39   \n","4  [Tomatillo-Red Chili Salsa (Hot), [Black Beans...    $16.98   \n","5  [Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou...    $10.98   \n","6                                                NaN     $1.69   \n","7  [Tomatillo Red Chili Salsa, [Fajita Vegetables...    $11.75   \n","8  [Tomatillo Green Chili Salsa, [Pinto Beans, Ch...     $9.25   \n","9  [Fresh Tomato Salsa, [Rice, Black Beans, Pinto...     $9.25   "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","chipo.head(10)"]},{"cell_type":"markdown","metadata":{"id":"36C01D752F674F67A478AE1F342C6E8B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 数据集中有多少个列(columns)"]},{"cell_type":"code","execution_count":236,"metadata":{"collapsed":false,"id":"6613EBD353BB4D6F8AF5D81D466D0A2C","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["5"]},"execution_count":236,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","chipo.shape[1]"]},{"cell_type":"markdown","metadata":{"id":"20803063BBA5436891F360DB28FBFC9C","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 打印出全部的列名称"]},{"cell_type":"code","execution_count":237,"metadata":{"collapsed":false,"id":"1D41C3783D3A42328EBAEAA18F306F00","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["Index(['order_id', 'quantity', 'item_name', 'choice_description',\n","       'item_price'],\n","      dtype='object')"]},"execution_count":237,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","chipo.columns"]},{"cell_type":"markdown","metadata":{"id":"9F31EFDDE39A434486D021321BD54BAA","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 数据集的索引是怎样的"]},{"cell_type":"code","execution_count":238,"metadata":{"collapsed":false,"id":"360C96EEF1A44DA7BA9F2868794BB2F3","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["RangeIndex(start=0, stop=4622, step=1)"]},"execution_count":238,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","chipo.index"]},{"cell_type":"markdown","metadata":{"id":"8DEEE30F80DA472C8BE5E1CE46C10DA1","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤9 被下单数最多商品(item)是什么?"]},{"cell_type":"code","execution_count":239,"metadata":{"collapsed":false,"id":"6CF50B46BB154597862876451D94B56E","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>item_name</th>\n","      <th>quantity</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>17</th>\n","      <td>Chicken Bowl</td>\n","      <td>761</td>\n","    </tr>\n","    <tr>\n","      <th>18</th>\n","      <td>Chicken Burrito</td>\n","      <td>591</td>\n","    </tr>\n","    <tr>\n","      <th>25</th>\n","      <td>Chips and Guacamole</td>\n","      <td>506</td>\n","    </tr>\n","    <tr>\n","      <th>39</th>\n","      <td>Steak Burrito</td>\n","      <td>386</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>Canned Soft Drink</td>\n","      <td>351</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["              item_name  quantity\n","17         Chicken Bowl       761\n","18      Chicken Burrito       591\n","25  Chips and Guacamole       506\n","39        Steak Burrito       386\n","10    Canned Soft Drink       351"]},"execution_count":239,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码，做了修正\n","c = chipo[['item_name','quantity']].groupby(['item_name'],as_index=False).agg({'quantity':sum})\n","c.sort_values(['quantity'],ascending=False,inplace=True)\n","c.head()"]},{"cell_type":"markdown","metadata":{"id":"3FCD63E8DECE41F69F628F96BAE8BED6","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤10 在item_name这一列中，一共有多少种商品被下单？"]},{"cell_type":"code","execution_count":240,"metadata":{"collapsed":false,"id":"5EBAF985AFD746D9BCBD6F1A4C02A3DF","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["50"]},"execution_count":240,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","chipo['item_name'].nunique()"]},{"cell_type":"markdown","metadata":{"id":"41992A1FF1104EBA8E081CABA37A3789","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤11 在choice_description中，下单次数最多的商品是什么？"]},{"cell_type":"code","execution_count":241,"metadata":{"collapsed":false,"id":"EE93DCF6B6D040B98A3A3C42F19C96E7","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["[Diet Coke]                                                                          134\n","[Coke]                                                                               123\n","[Sprite]                                                                              77\n","[Fresh Tomato Salsa, [Rice, Black Beans, Cheese, Sour Cream, Lettuce]]                42\n","[Fresh Tomato Salsa, [Rice, Black Beans, Cheese, Sour Cream, Guacamole, Lettuce]]     40\n","Name: choice_description, dtype: int64"]},"execution_count":241,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码，存在一些小问题\n","chipo['choice_description'].value_counts().head()"]},{"cell_type":"markdown","metadata":{"id":"4B0F3135C107415D8294267590E85DEB","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤12 一共有多少商品被下单？"]},{"cell_type":"code","execution_count":242,"metadata":{"collapsed":false,"id":"4B7A876AD7B54DF38CDC177B77BDE81C","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["4972"]},"execution_count":242,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","total_items_orders = chipo['quantity'].sum()\n","total_items_orders"]},{"cell_type":"markdown","metadata":{"id":"87D08C714BD5474E87289C6369CDEE32","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤13 将item_price转换为浮点数"]},{"cell_type":"code","execution_count":243,"metadata":{"collapsed":false,"id":"EC9ED140244E448F82A120BD21FBB797","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","dollarizer = lambda x: float(x[1:-1])\n","chipo['item_price'] = chipo['item_price'].apply(dollarizer)"]},{"cell_type":"markdown","metadata":{"id":"90B1CFA500B3432685D36E0811322FA6","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤14 在该数据集对应的时期内，收入(revenue)是多少"]},{"cell_type":"code","execution_count":244,"metadata":{"collapsed":false,"id":"A77F1FEB032E42A19B8F761D86E38EE9","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["39237.02"]},"execution_count":244,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码,已经做更正\n","chipo['sub_total'] = round(chipo['item_price'] * chipo['quantity'],2)\n","chipo['sub_total'].sum()"]},{"cell_type":"markdown","metadata":{"id":"FA9D729D7447428AB721A1F110EB8AE5","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤15 在该数据集对应的时期内，一共有多少订单？"]},{"cell_type":"code","execution_count":245,"metadata":{"collapsed":false,"id":"AF9C2C658624443C8EBA17CB129B5404","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["1834"]},"execution_count":245,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","chipo['order_id'].nunique()"]},{"cell_type":"markdown","metadata":{"id":"012BFF099BF642AC803BAF3733F6FCD9","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤16 每一单(order)对应的平均总价是多少？"]},{"cell_type":"code","execution_count":246,"metadata":{"collapsed":false,"id":"A8A6A6BE4DD3423E9A68BCDCAA54D9D7","jupyter":{},"mdEditEnable":false,"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["21.39423118865867"]},"execution_count":246,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码，已经做过更正\n","chipo[['order_id','sub_total']].groupby(by=['order_id']\n",").agg({'sub_total':'sum'})['sub_total'].mean()"]},{"cell_type":"markdown","metadata":{"id":"1908B5E031E34422ABD9A810738F5274","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤17 一共有多少种不同的商品被售出？"]},{"cell_type":"code","execution_count":247,"metadata":{"collapsed":false,"id":"0263B0740829494A8E2030859F1117D8","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["50"]},"execution_count":247,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","chipo['item_name'].nunique()"]},{"cell_type":"markdown","metadata":{"id":"ED5E8E7701BE414880F87B1C0AED18A5","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"65818C7767B54230816B241B20786D13","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习2-数据过滤与排序\n","## 探索2012欧洲杯数据\n","![image description](https://cdn.kesci.com/images/lab_upload/1508342554087_23763.jpeg)"]},{"cell_type":"markdown","metadata":{"id":"A41FAA4DC5FF461686FF518FE61F02C9","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"B5885483F9184D3E8A0F6C8698C97C6B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 - 导入必要的库"]},{"cell_type":"code","execution_count":248,"metadata":{"collapsed":false,"id":"9B6335351C2F41AE95DB3074C951A5EF","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd"]},{"cell_type":"markdown","metadata":{"id":"C85B6DE1B72240BE8318BE25FF67A03B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 - 从以下地址导入数据集"]},{"cell_type":"code","execution_count":249,"metadata":{"collapsed":false,"id":"700B6577DD7D472AA84D6629A2F42BA4","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path2 = \"../input/pandas_exercise/exercise_data/Euro2012_stats.csv\"      # Euro2012_stats.csv"]},{"cell_type":"markdown","metadata":{"id":"F5F9D72407874AA7B04F507D333506D0","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 - 将数据集命名为euro12"]},{"cell_type":"code","execution_count":250,"metadata":{"collapsed":false,"id":"1877678AEBAF49E88E3E1551B8230BF9","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Goals</th>\n","      <th>Shots on target</th>\n","      <th>Shots off target</th>\n","      <th>Shooting Accuracy</th>\n","      <th>% Goals-to-shots</th>\n","      <th>Total shots (inc. Blocked)</th>\n","      <th>Hit Woodwork</th>\n","      <th>Penalty goals</th>\n","      <th>Penalties not scored</th>\n","      <th>...</th>\n","      <th>Saves made</th>\n","      <th>Saves-to-shots ratio</th>\n","      <th>Fouls Won</th>\n","      <th>Fouls Conceded</th>\n","      <th>Offsides</th>\n","      <th>Yellow Cards</th>\n","      <th>Red Cards</th>\n","      <th>Subs on</th>\n","      <th>Subs off</th>\n","      <th>Players Used</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Croatia</td>\n","      <td>4</td>\n","      <td>13</td>\n","      <td>12</td>\n","      <td>51.9%</td>\n","      <td>16.0%</td>\n","      <td>32</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>13</td>\n","      <td>81.3%</td>\n","      <td>41</td>\n","      <td>62</td>\n","      <td>2</td>\n","      <td>9</td>\n","      <td>0</td>\n","      <td>9</td>\n","      <td>9</td>\n","      <td>16</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Czech Republic</td>\n","      <td>4</td>\n","      <td>13</td>\n","      <td>18</td>\n","      <td>41.9%</td>\n","      <td>12.9%</td>\n","      <td>39</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>9</td>\n","      <td>60.1%</td>\n","      <td>53</td>\n","      <td>73</td>\n","      <td>8</td>\n","      <td>7</td>\n","      <td>0</td>\n","      <td>11</td>\n","      <td>11</td>\n","      <td>19</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Denmark</td>\n","      <td>4</td>\n","      <td>10</td>\n","      <td>10</td>\n","      <td>50.0%</td>\n","      <td>20.0%</td>\n","      <td>27</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>10</td>\n","      <td>66.7%</td>\n","      <td>25</td>\n","      <td>38</td>\n","      <td>8</td>\n","      <td>4</td>\n","      <td>0</td>\n","      <td>7</td>\n","      <td>7</td>\n","      <td>15</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>England</td>\n","      <td>5</td>\n","      <td>11</td>\n","      <td>18</td>\n","      <td>50.0%</td>\n","      <td>17.2%</td>\n","      <td>40</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>22</td>\n","      <td>88.1%</td>\n","      <td>43</td>\n","      <td>45</td>\n","      <td>6</td>\n","      <td>5</td>\n","      <td>0</td>\n","      <td>11</td>\n","      <td>11</td>\n","      <td>16</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>France</td>\n","      <td>3</td>\n","      <td>22</td>\n","      <td>24</td>\n","      <td>37.9%</td>\n","      <td>6.5%</td>\n","      <td>65</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>6</td>\n","      <td>54.6%</td>\n","      <td>36</td>\n","      <td>51</td>\n","      <td>5</td>\n","      <td>6</td>\n","      <td>0</td>\n","      <td>11</td>\n","      <td>11</td>\n","      <td>19</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>Germany</td>\n","      <td>10</td>\n","      <td>32</td>\n","      <td>32</td>\n","      <td>47.8%</td>\n","      <td>15.6%</td>\n","      <td>80</td>\n","      <td>2</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>10</td>\n","      <td>62.6%</td>\n","      <td>63</td>\n","      <td>49</td>\n","      <td>12</td>\n","      <td>4</td>\n","      <td>0</td>\n","      <td>15</td>\n","      <td>15</td>\n","      <td>17</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>Greece</td>\n","      <td>5</td>\n","      <td>8</td>\n","      <td>18</td>\n","      <td>30.7%</td>\n","      <td>19.2%</td>\n","      <td>32</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>...</td>\n","      <td>13</td>\n","      <td>65.1%</td>\n","      <td>67</td>\n","      <td>48</td>\n","      <td>12</td>\n","      <td>9</td>\n","      <td>1</td>\n","      <td>12</td>\n","      <td>12</td>\n","      <td>20</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Italy</td>\n","      <td>6</td>\n","      <td>34</td>\n","      <td>45</td>\n","      <td>43.0%</td>\n","      <td>7.5%</td>\n","      <td>110</td>\n","      <td>2</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>20</td>\n","      <td>74.1%</td>\n","      <td>101</td>\n","      <td>89</td>\n","      <td>16</td>\n","      <td>16</td>\n","      <td>0</td>\n","      <td>18</td>\n","      <td>18</td>\n","      <td>19</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>Netherlands</td>\n","      <td>2</td>\n","      <td>12</td>\n","      <td>36</td>\n","      <td>25.0%</td>\n","      <td>4.1%</td>\n","      <td>60</td>\n","      <td>2</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>12</td>\n","      <td>70.6%</td>\n","      <td>35</td>\n","      <td>30</td>\n","      <td>3</td>\n","      <td>5</td>\n","      <td>0</td>\n","      <td>7</td>\n","      <td>7</td>\n","      <td>15</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>Poland</td>\n","      <td>2</td>\n","      <td>15</td>\n","      <td>23</td>\n","      <td>39.4%</td>\n","      <td>5.2%</td>\n","      <td>48</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>6</td>\n","      <td>66.7%</td>\n","      <td>48</td>\n","      <td>56</td>\n","      <td>3</td>\n","      <td>7</td>\n","      <td>1</td>\n","      <td>7</td>\n","      <td>7</td>\n","      <td>17</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>Portugal</td>\n","      <td>6</td>\n","      <td>22</td>\n","      <td>42</td>\n","      <td>34.3%</td>\n","      <td>9.3%</td>\n","      <td>82</td>\n","      <td>6</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>10</td>\n","      <td>71.5%</td>\n","      <td>73</td>\n","      <td>90</td>\n","      <td>10</td>\n","      <td>12</td>\n","      <td>0</td>\n","      <td>14</td>\n","      <td>14</td>\n","      <td>16</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>Republic of Ireland</td>\n","      <td>1</td>\n","      <td>7</td>\n","      <td>12</td>\n","      <td>36.8%</td>\n","      <td>5.2%</td>\n","      <td>28</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>17</td>\n","      <td>65.4%</td>\n","      <td>43</td>\n","      <td>51</td>\n","      <td>11</td>\n","      <td>6</td>\n","      <td>1</td>\n","      <td>10</td>\n","      <td>10</td>\n","      <td>17</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>Russia</td>\n","      <td>5</td>\n","      <td>9</td>\n","      <td>31</td>\n","      <td>22.5%</td>\n","      <td>12.5%</td>\n","      <td>59</td>\n","      <td>2</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>10</td>\n","      <td>77.0%</td>\n","      <td>34</td>\n","      <td>43</td>\n","      <td>4</td>\n","      <td>6</td>\n","      <td>0</td>\n","      <td>7</td>\n","      <td>7</td>\n","      <td>16</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>Spain</td>\n","      <td>12</td>\n","      <td>42</td>\n","      <td>33</td>\n","      <td>55.9%</td>\n","      <td>16.0%</td>\n","      <td>100</td>\n","      <td>0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>15</td>\n","      <td>93.8%</td>\n","      <td>102</td>\n","      <td>83</td>\n","      <td>19</td>\n","      <td>11</td>\n","      <td>0</td>\n","      <td>17</td>\n","      <td>17</td>\n","      <td>18</td>\n","    </tr>\n","    <tr>\n","      <th>14</th>\n","      <td>Sweden</td>\n","      <td>5</td>\n","      <td>17</td>\n","      <td>19</td>\n","      <td>47.2%</td>\n","      <td>13.8%</td>\n","      <td>39</td>\n","      <td>3</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>8</td>\n","      <td>61.6%</td>\n","      <td>35</td>\n","      <td>51</td>\n","      <td>7</td>\n","      <td>7</td>\n","      <td>0</td>\n","      <td>9</td>\n","      <td>9</td>\n","      <td>18</td>\n","    </tr>\n","    <tr>\n","      <th>15</th>\n","      <td>Ukraine</td>\n","      <td>2</td>\n","      <td>7</td>\n","      <td>26</td>\n","      <td>21.2%</td>\n","      <td>6.0%</td>\n","      <td>38</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>13</td>\n","      <td>76.5%</td>\n","      <td>48</td>\n","      <td>31</td>\n","      <td>4</td>\n","      <td>5</td>\n","      <td>0</td>\n","      <td>9</td>\n","      <td>9</td>\n","      <td>18</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>16 rows × 35 columns</p>\n","</div>"],"text/plain":["                   Team  Goals  Shots on target  Shots off target  \\\n","0               Croatia      4               13                12   \n","1        Czech Republic      4               13                18   \n","2               Denmark      4               10                10   \n","3               England      5               11                18   \n","4                France      3               22                24   \n","5               Germany     10               32                32   \n","6                Greece      5                8                18   \n","7                 Italy      6               34                45   \n","8           Netherlands      2               12                36   \n","9                Poland      2               15                23   \n","10             Portugal      6               22                42   \n","11  Republic of Ireland      1                7                12   \n","12               Russia      5                9                31   \n","13                Spain     12               42                33   \n","14               Sweden      5               17                19   \n","15              Ukraine      2                7                26   \n","\n","   Shooting Accuracy % Goals-to-shots  Total shots (inc. Blocked)  \\\n","0              51.9%            16.0%                          32   \n","1              41.9%            12.9%                          39   \n","2              50.0%            20.0%                          27   \n","3              50.0%            17.2%                          40   \n","4              37.9%             6.5%                          65   \n","5              47.8%            15.6%                          80   \n","6              30.7%            19.2%                          32   \n","7              43.0%             7.5%                         110   \n","8              25.0%             4.1%                          60   \n","9              39.4%             5.2%                          48   \n","10             34.3%             9.3%                          82   \n","11             36.8%             5.2%                          28   \n","12             22.5%            12.5%                          59   \n","13             55.9%            16.0%                         100   \n","14             47.2%            13.8%                          39   \n","15             21.2%             6.0%                          38   \n","\n","    Hit Woodwork  Penalty goals  Penalties not scored      ...       \\\n","0              0              0                     0      ...        \n","1              0              0                     0      ...        \n","2              1              0                     0      ...        \n","3              0              0                     0      ...        \n","4              1              0                     0      ...        \n","5              2              1                     0      ...        \n","6              1              1                     1      ...        \n","7              2              0                     0      ...        \n","8              2              0                     0      ...        \n","9              0              0                     0      ...        \n","10             6              0                     0      ...        \n","11             0              0                     0      ...        \n","12             2              0                     0      ...        \n","13             0              1                     0      ...        \n","14             3              0                     0      ...        \n","15             0              0                     0      ...        \n","\n","    Saves made  Saves-to-shots ratio  Fouls Won Fouls Conceded  Offsides  \\\n","0           13                 81.3%         41             62         2   \n","1            9                 60.1%         53             73         8   \n","2           10                 66.7%         25             38         8   \n","3           22                 88.1%         43             45         6   \n","4            6                 54.6%         36             51         5   \n","5           10                 62.6%         63             49        12   \n","6           13                 65.1%         67             48        12   \n","7           20                 74.1%        101             89        16   \n","8           12                 70.6%         35             30         3   \n","9            6                 66.7%         48             56         3   \n","10          10                 71.5%         73             90        10   \n","11          17                 65.4%         43             51        11   \n","12          10                 77.0%         34             43         4   \n","13          15                 93.8%        102             83        19   \n","14           8                 61.6%         35             51         7   \n","15          13                 76.5%         48             31         4   \n","\n","    Yellow Cards  Red Cards  Subs on  Subs off  Players Used  \n","0              9          0        9         9            16  \n","1              7          0       11        11            19  \n","2              4          0        7         7            15  \n","3              5          0       11        11            16  \n","4              6          0       11        11            19  \n","5              4          0       15        15            17  \n","6              9          1       12        12            20  \n","7             16          0       18        18            19  \n","8              5          0        7         7            15  \n","9              7          1        7         7            17  \n","10            12          0       14        14            16  \n","11             6          1       10        10            17  \n","12             6          0        7         7            16  \n","13            11          0       17        17            18  \n","14             7          0        9         9            18  \n","15             5          0        9         9            18  \n","\n","[16 rows x 35 columns]"]},"execution_count":250,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12 = pd.read_csv(path2)\n","euro12"]},{"cell_type":"markdown","metadata":{"id":"361E9D2010D04EE9B87F2852FE109674","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 只选取 ```Goals``` 这一列"]},{"cell_type":"code","execution_count":251,"metadata":{"collapsed":false,"id":"EC00B2F415C042138AAF9A4CDFC9C082","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["0      4\n","1      4\n","2      4\n","3      5\n","4      3\n","5     10\n","6      5\n","7      6\n","8      2\n","9      2\n","10     6\n","11     1\n","12     5\n","13    12\n","14     5\n","15     2\n","Name: Goals, dtype: int64"]},"execution_count":251,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12.Goals"]},{"cell_type":"markdown","metadata":{"id":"9CBF9BA701B048449D1A4DD2FEA2F140","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 有多少球队参与了2012欧洲杯？"]},{"cell_type":"code","execution_count":252,"metadata":{"collapsed":false,"id":"17A2EC8280584B3798DCD3B62D61EED9","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["16"]},"execution_count":252,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12.shape[0]"]},{"cell_type":"markdown","metadata":{"id":"484D858BAF1D4611ADF9DFD9149D2C2B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 该数据集中一共有多少列(columns)?"]},{"cell_type":"code","execution_count":253,"metadata":{"collapsed":false,"id":"180424EB08CF49B2BE7D58C064239AD6","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["<class 'pandas.core.frame.DataFrame'>\n","RangeIndex: 16 entries, 0 to 15\n","Data columns (total 35 columns):\n","Team                          16 non-null object\n","Goals                         16 non-null int64\n","Shots on target               16 non-null int64\n","Shots off target              16 non-null int64\n","Shooting Accuracy             16 non-null object\n","% Goals-to-shots              16 non-null object\n","Total shots (inc. Blocked)    16 non-null int64\n","Hit Woodwork                  16 non-null int64\n","Penalty goals                 16 non-null int64\n","Penalties not scored          16 non-null int64\n","Headed goals                  16 non-null int64\n","Passes                        16 non-null int64\n","Passes completed              16 non-null int64\n","Passing Accuracy              16 non-null object\n","Touches                       16 non-null int64\n","Crosses                       16 non-null int64\n","Dribbles                      16 non-null int64\n","Corners Taken                 16 non-null int64\n","Tackles                       16 non-null int64\n","Clearances                    16 non-null int64\n","Interceptions                 16 non-null int64\n","Clearances off line           15 non-null float64\n","Clean Sheets                  16 non-null int64\n","Blocks                        16 non-null int64\n","Goals conceded                16 non-null int64\n","Saves made                    16 non-null int64\n","Saves-to-shots ratio          16 non-null object\n","Fouls Won                     16 non-null int64\n","Fouls Conceded                16 non-null int64\n","Offsides                      16 non-null int64\n","Yellow Cards                  16 non-null int64\n","Red Cards                     16 non-null int64\n","Subs on                       16 non-null int64\n","Subs off                      16 non-null int64\n","Players Used                  16 non-null int64\n","dtypes: float64(1), int64(29), object(5)\n","memory usage: 4.5+ KB\n"]}],"source":["# 运行以下代码\n","euro12.info()"]},{"cell_type":"markdown","metadata":{"id":"55517897DC62416AAA240818C2012C0B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 将数据集中的列Team, Yellow Cards和Red Cards单独存为一个名叫discipline的数据框"]},{"cell_type":"code","execution_count":254,"metadata":{"collapsed":false,"id":"8E8491001AAE4C15BD13EE14649C511E","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Yellow Cards</th>\n","      <th>Red Cards</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Croatia</td>\n","      <td>9</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Czech Republic</td>\n","      <td>7</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Denmark</td>\n","      <td>4</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>England</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>France</td>\n","      <td>6</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>Germany</td>\n","      <td>4</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>Greece</td>\n","      <td>9</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Italy</td>\n","      <td>16</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>Netherlands</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>Poland</td>\n","      <td>7</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>Portugal</td>\n","      <td>12</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>Republic of Ireland</td>\n","      <td>6</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>Russia</td>\n","      <td>6</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>Spain</td>\n","      <td>11</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>14</th>\n","      <td>Sweden</td>\n","      <td>7</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>15</th>\n","      <td>Ukraine</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["                   Team  Yellow Cards  Red Cards\n","0               Croatia             9          0\n","1        Czech Republic             7          0\n","2               Denmark             4          0\n","3               England             5          0\n","4                France             6          0\n","5               Germany             4          0\n","6                Greece             9          1\n","7                 Italy            16          0\n","8           Netherlands             5          0\n","9                Poland             7          1\n","10             Portugal            12          0\n","11  Republic of Ireland             6          1\n","12               Russia             6          0\n","13                Spain            11          0\n","14               Sweden             7          0\n","15              Ukraine             5          0"]},"execution_count":254,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","discipline = euro12[['Team', 'Yellow Cards', 'Red Cards']]\n","discipline"]},{"cell_type":"markdown","metadata":{"id":"4BB0382A2407479ABA9BA67774548CA0","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 对数据框discipline按照先Red Cards再Yellow Cards进行排序 "]},{"cell_type":"code","execution_count":255,"metadata":{"collapsed":false,"id":"7E5FB7A44B6C49BC8B2EB7B3F9CD2ED2","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Yellow Cards</th>\n","      <th>Red Cards</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>6</th>\n","      <td>Greece</td>\n","      <td>9</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>Poland</td>\n","      <td>7</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>Republic of Ireland</td>\n","      <td>6</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Italy</td>\n","      <td>16</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>Portugal</td>\n","      <td>12</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>Spain</td>\n","      <td>11</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>0</th>\n","      <td>Croatia</td>\n","      <td>9</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Czech Republic</td>\n","      <td>7</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>14</th>\n","      <td>Sweden</td>\n","      <td>7</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>France</td>\n","      <td>6</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>Russia</td>\n","      <td>6</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>England</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>Netherlands</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>15</th>\n","      <td>Ukraine</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Denmark</td>\n","      <td>4</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>Germany</td>\n","      <td>4</td>\n","      <td>0</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["                   Team  Yellow Cards  Red Cards\n","6                Greece             9          1\n","9                Poland             7          1\n","11  Republic of Ireland             6          1\n","7                 Italy            16          0\n","10             Portugal            12          0\n","13                Spain            11          0\n","0               Croatia             9          0\n","1        Czech Republic             7          0\n","14               Sweden             7          0\n","4                France             6          0\n","12               Russia             6          0\n","3               England             5          0\n","8           Netherlands             5          0\n","15              Ukraine             5          0\n","2               Denmark             4          0\n","5               Germany             4          0"]},"execution_count":255,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","discipline.sort_values(['Red Cards', 'Yellow Cards'], ascending = False)"]},{"cell_type":"markdown","metadata":{"id":"98B9C78B09E347C98FA251887B9728DA","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤9 计算每个球队拿到的黄牌数的平均值"]},{"cell_type":"code","execution_count":256,"metadata":{"collapsed":false,"id":"942E95CF38AD4674A8DBDB2EBE12028D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["7.0"]},"execution_count":256,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","round(discipline['Yellow Cards'].mean())"]},{"cell_type":"markdown","metadata":{"id":"04BA8FF663004CF28DFA7833F6F52C8B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤10 找到进球数Goals超过6的球队数据"]},{"cell_type":"code","execution_count":257,"metadata":{"collapsed":false,"id":"04EEE9F5D6EB467D8238BB106CB5AC7E","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Goals</th>\n","      <th>Shots on target</th>\n","      <th>Shots off target</th>\n","      <th>Shooting Accuracy</th>\n","      <th>% Goals-to-shots</th>\n","      <th>Total shots (inc. Blocked)</th>\n","      <th>Hit Woodwork</th>\n","      <th>Penalty goals</th>\n","      <th>Penalties not scored</th>\n","      <th>...</th>\n","      <th>Saves made</th>\n","      <th>Saves-to-shots ratio</th>\n","      <th>Fouls Won</th>\n","      <th>Fouls Conceded</th>\n","      <th>Offsides</th>\n","      <th>Yellow Cards</th>\n","      <th>Red Cards</th>\n","      <th>Subs on</th>\n","      <th>Subs off</th>\n","      <th>Players Used</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>5</th>\n","      <td>Germany</td>\n","      <td>10</td>\n","      <td>32</td>\n","      <td>32</td>\n","      <td>47.8%</td>\n","      <td>15.6%</td>\n","      <td>80</td>\n","      <td>2</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>10</td>\n","      <td>62.6%</td>\n","      <td>63</td>\n","      <td>49</td>\n","      <td>12</td>\n","      <td>4</td>\n","      <td>0</td>\n","      <td>15</td>\n","      <td>15</td>\n","      <td>17</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>Spain</td>\n","      <td>12</td>\n","      <td>42</td>\n","      <td>33</td>\n","      <td>55.9%</td>\n","      <td>16.0%</td>\n","      <td>100</td>\n","      <td>0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>15</td>\n","      <td>93.8%</td>\n","      <td>102</td>\n","      <td>83</td>\n","      <td>19</td>\n","      <td>11</td>\n","      <td>0</td>\n","      <td>17</td>\n","      <td>17</td>\n","      <td>18</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>2 rows × 35 columns</p>\n","</div>"],"text/plain":["       Team  Goals  Shots on target  Shots off target Shooting Accuracy  \\\n","5   Germany     10               32                32             47.8%   \n","13    Spain     12               42                33             55.9%   \n","\n","   % Goals-to-shots  Total shots (inc. Blocked)  Hit Woodwork  Penalty goals  \\\n","5             15.6%                          80             2              1   \n","13            16.0%                         100             0              1   \n","\n","    Penalties not scored      ...       Saves made  Saves-to-shots ratio  \\\n","5                      0      ...               10                 62.6%   \n","13                     0      ...               15                 93.8%   \n","\n","    Fouls Won Fouls Conceded  Offsides  Yellow Cards  Red Cards  Subs on  \\\n","5          63             49        12             4          0       15   \n","13        102             83        19            11          0       17   \n","\n","    Subs off  Players Used  \n","5         15            17  \n","13        17            18  \n","\n","[2 rows x 35 columns]"]},"execution_count":257,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12[euro12.Goals > 6]"]},{"cell_type":"markdown","metadata":{"id":"8E7F8EDD463544788BDDFE4CDC519ABE","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤11 选取以字母G开头的球队数据"]},{"cell_type":"code","execution_count":258,"metadata":{"collapsed":false,"id":"24D05579E3C945D88FAB8C93F0F296B5","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Goals</th>\n","      <th>Shots on target</th>\n","      <th>Shots off target</th>\n","      <th>Shooting Accuracy</th>\n","      <th>% Goals-to-shots</th>\n","      <th>Total shots (inc. Blocked)</th>\n","      <th>Hit Woodwork</th>\n","      <th>Penalty goals</th>\n","      <th>Penalties not scored</th>\n","      <th>...</th>\n","      <th>Saves made</th>\n","      <th>Saves-to-shots ratio</th>\n","      <th>Fouls Won</th>\n","      <th>Fouls Conceded</th>\n","      <th>Offsides</th>\n","      <th>Yellow Cards</th>\n","      <th>Red Cards</th>\n","      <th>Subs on</th>\n","      <th>Subs off</th>\n","      <th>Players Used</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>5</th>\n","      <td>Germany</td>\n","      <td>10</td>\n","      <td>32</td>\n","      <td>32</td>\n","      <td>47.8%</td>\n","      <td>15.6%</td>\n","      <td>80</td>\n","      <td>2</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>10</td>\n","      <td>62.6%</td>\n","      <td>63</td>\n","      <td>49</td>\n","      <td>12</td>\n","      <td>4</td>\n","      <td>0</td>\n","      <td>15</td>\n","      <td>15</td>\n","      <td>17</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>Greece</td>\n","      <td>5</td>\n","      <td>8</td>\n","      <td>18</td>\n","      <td>30.7%</td>\n","      <td>19.2%</td>\n","      <td>32</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>...</td>\n","      <td>13</td>\n","      <td>65.1%</td>\n","      <td>67</td>\n","      <td>48</td>\n","      <td>12</td>\n","      <td>9</td>\n","      <td>1</td>\n","      <td>12</td>\n","      <td>12</td>\n","      <td>20</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>2 rows × 35 columns</p>\n","</div>"],"text/plain":["      Team  Goals  Shots on target  Shots off target Shooting Accuracy  \\\n","5  Germany     10               32                32             47.8%   \n","6   Greece      5                8                18             30.7%   \n","\n","  % Goals-to-shots  Total shots (inc. Blocked)  Hit Woodwork  Penalty goals  \\\n","5            15.6%                          80             2              1   \n","6            19.2%                          32             1              1   \n","\n","   Penalties not scored      ...       Saves made  Saves-to-shots ratio  \\\n","5                     0      ...               10                 62.6%   \n","6                     1      ...               13                 65.1%   \n","\n","   Fouls Won Fouls Conceded  Offsides  Yellow Cards  Red Cards  Subs on  \\\n","5         63             49        12             4          0       15   \n","6         67             48        12             9          1       12   \n","\n","   Subs off  Players Used  \n","5        15            17  \n","6        12            20  \n","\n","[2 rows x 35 columns]"]},"execution_count":258,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12[euro12.Team.str.startswith('G')]"]},{"cell_type":"markdown","metadata":{"id":"9381FA4AFE33435ABDD35D49BAC96AA7","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤12 选取前7列"]},{"cell_type":"code","execution_count":259,"metadata":{"collapsed":false,"id":"2981A00C7E2B4257B21345E7713415A4","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Goals</th>\n","      <th>Shots on target</th>\n","      <th>Shots off target</th>\n","      <th>Shooting Accuracy</th>\n","      <th>% Goals-to-shots</th>\n","      <th>Total shots (inc. Blocked)</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Croatia</td>\n","      <td>4</td>\n","      <td>13</td>\n","      <td>12</td>\n","      <td>51.9%</td>\n","      <td>16.0%</td>\n","      <td>32</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Czech Republic</td>\n","      <td>4</td>\n","      <td>13</td>\n","      <td>18</td>\n","      <td>41.9%</td>\n","      <td>12.9%</td>\n","      <td>39</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Denmark</td>\n","      <td>4</td>\n","      <td>10</td>\n","      <td>10</td>\n","      <td>50.0%</td>\n","      <td>20.0%</td>\n","      <td>27</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>England</td>\n","      <td>5</td>\n","      <td>11</td>\n","      <td>18</td>\n","      <td>50.0%</td>\n","      <td>17.2%</td>\n","      <td>40</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>France</td>\n","      <td>3</td>\n","      <td>22</td>\n","      <td>24</td>\n","      <td>37.9%</td>\n","      <td>6.5%</td>\n","      <td>65</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>Germany</td>\n","      <td>10</td>\n","      <td>32</td>\n","      <td>32</td>\n","      <td>47.8%</td>\n","      <td>15.6%</td>\n","      <td>80</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>Greece</td>\n","      <td>5</td>\n","      <td>8</td>\n","      <td>18</td>\n","      <td>30.7%</td>\n","      <td>19.2%</td>\n","      <td>32</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Italy</td>\n","      <td>6</td>\n","      <td>34</td>\n","      <td>45</td>\n","      <td>43.0%</td>\n","      <td>7.5%</td>\n","      <td>110</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>Netherlands</td>\n","      <td>2</td>\n","      <td>12</td>\n","      <td>36</td>\n","      <td>25.0%</td>\n","      <td>4.1%</td>\n","      <td>60</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>Poland</td>\n","      <td>2</td>\n","      <td>15</td>\n","      <td>23</td>\n","      <td>39.4%</td>\n","      <td>5.2%</td>\n","      <td>48</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>Portugal</td>\n","      <td>6</td>\n","      <td>22</td>\n","      <td>42</td>\n","      <td>34.3%</td>\n","      <td>9.3%</td>\n","      <td>82</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>Republic of Ireland</td>\n","      <td>1</td>\n","      <td>7</td>\n","      <td>12</td>\n","      <td>36.8%</td>\n","      <td>5.2%</td>\n","      <td>28</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>Russia</td>\n","      <td>5</td>\n","      <td>9</td>\n","      <td>31</td>\n","      <td>22.5%</td>\n","      <td>12.5%</td>\n","      <td>59</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>Spain</td>\n","      <td>12</td>\n","      <td>42</td>\n","      <td>33</td>\n","      <td>55.9%</td>\n","      <td>16.0%</td>\n","      <td>100</td>\n","    </tr>\n","    <tr>\n","      <th>14</th>\n","      <td>Sweden</td>\n","      <td>5</td>\n","      <td>17</td>\n","      <td>19</td>\n","      <td>47.2%</td>\n","      <td>13.8%</td>\n","      <td>39</td>\n","    </tr>\n","    <tr>\n","      <th>15</th>\n","      <td>Ukraine</td>\n","      <td>2</td>\n","      <td>7</td>\n","      <td>26</td>\n","      <td>21.2%</td>\n","      <td>6.0%</td>\n","      <td>38</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["                   Team  Goals  Shots on target  Shots off target  \\\n","0               Croatia      4               13                12   \n","1        Czech Republic      4               13                18   \n","2               Denmark      4               10                10   \n","3               England      5               11                18   \n","4                France      3               22                24   \n","5               Germany     10               32                32   \n","6                Greece      5                8                18   \n","7                 Italy      6               34                45   \n","8           Netherlands      2               12                36   \n","9                Poland      2               15                23   \n","10             Portugal      6               22                42   \n","11  Republic of Ireland      1                7                12   \n","12               Russia      5                9                31   \n","13                Spain     12               42                33   \n","14               Sweden      5               17                19   \n","15              Ukraine      2                7                26   \n","\n","   Shooting Accuracy % Goals-to-shots  Total shots (inc. Blocked)  \n","0              51.9%            16.0%                          32  \n","1              41.9%            12.9%                          39  \n","2              50.0%            20.0%                          27  \n","3              50.0%            17.2%                          40  \n","4              37.9%             6.5%                          65  \n","5              47.8%            15.6%                          80  \n","6              30.7%            19.2%                          32  \n","7              43.0%             7.5%                         110  \n","8              25.0%             4.1%                          60  \n","9              39.4%             5.2%                          48  \n","10             34.3%             9.3%                          82  \n","11             36.8%             5.2%                          28  \n","12             22.5%            12.5%                          59  \n","13             55.9%            16.0%                         100  \n","14             47.2%            13.8%                          39  \n","15             21.2%             6.0%                          38  "]},"execution_count":259,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12.iloc[: , 0:7]"]},{"cell_type":"markdown","metadata":{"id":"2E2F3DFD381F440495D15AF51B95F213","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤13 选取除了最后3列之外的全部列"]},{"cell_type":"code","execution_count":260,"metadata":{"collapsed":false,"id":"3872CDAC11314B8A9D6005345ACA8028","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Goals</th>\n","      <th>Shots on target</th>\n","      <th>Shots off target</th>\n","      <th>Shooting Accuracy</th>\n","      <th>% Goals-to-shots</th>\n","      <th>Total shots (inc. Blocked)</th>\n","      <th>Hit Woodwork</th>\n","      <th>Penalty goals</th>\n","      <th>Penalties not scored</th>\n","      <th>...</th>\n","      <th>Clean Sheets</th>\n","      <th>Blocks</th>\n","      <th>Goals conceded</th>\n","      <th>Saves made</th>\n","      <th>Saves-to-shots ratio</th>\n","      <th>Fouls Won</th>\n","      <th>Fouls Conceded</th>\n","      <th>Offsides</th>\n","      <th>Yellow Cards</th>\n","      <th>Red Cards</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Croatia</td>\n","      <td>4</td>\n","      <td>13</td>\n","      <td>12</td>\n","      <td>51.9%</td>\n","      <td>16.0%</td>\n","      <td>32</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>0</td>\n","      <td>10</td>\n","      <td>3</td>\n","      <td>13</td>\n","      <td>81.3%</td>\n","      <td>41</td>\n","      <td>62</td>\n","      <td>2</td>\n","      <td>9</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Czech Republic</td>\n","      <td>4</td>\n","      <td>13</td>\n","      <td>18</td>\n","      <td>41.9%</td>\n","      <td>12.9%</td>\n","      <td>39</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>10</td>\n","      <td>6</td>\n","      <td>9</td>\n","      <td>60.1%</td>\n","      <td>53</td>\n","      <td>73</td>\n","      <td>8</td>\n","      <td>7</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Denmark</td>\n","      <td>4</td>\n","      <td>10</td>\n","      <td>10</td>\n","      <td>50.0%</td>\n","      <td>20.0%</td>\n","      <td>27</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>10</td>\n","      <td>5</td>\n","      <td>10</td>\n","      <td>66.7%</td>\n","      <td>25</td>\n","      <td>38</td>\n","      <td>8</td>\n","      <td>4</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>England</td>\n","      <td>5</td>\n","      <td>11</td>\n","      <td>18</td>\n","      <td>50.0%</td>\n","      <td>17.2%</td>\n","      <td>40</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>2</td>\n","      <td>29</td>\n","      <td>3</td>\n","      <td>22</td>\n","      <td>88.1%</td>\n","      <td>43</td>\n","      <td>45</td>\n","      <td>6</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>France</td>\n","      <td>3</td>\n","      <td>22</td>\n","      <td>24</td>\n","      <td>37.9%</td>\n","      <td>6.5%</td>\n","      <td>65</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>7</td>\n","      <td>5</td>\n","      <td>6</td>\n","      <td>54.6%</td>\n","      <td>36</td>\n","      <td>51</td>\n","      <td>5</td>\n","      <td>6</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>Germany</td>\n","      <td>10</td>\n","      <td>32</td>\n","      <td>32</td>\n","      <td>47.8%</td>\n","      <td>15.6%</td>\n","      <td>80</td>\n","      <td>2</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>11</td>\n","      <td>6</td>\n","      <td>10</td>\n","      <td>62.6%</td>\n","      <td>63</td>\n","      <td>49</td>\n","      <td>12</td>\n","      <td>4</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>Greece</td>\n","      <td>5</td>\n","      <td>8</td>\n","      <td>18</td>\n","      <td>30.7%</td>\n","      <td>19.2%</td>\n","      <td>32</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>23</td>\n","      <td>7</td>\n","      <td>13</td>\n","      <td>65.1%</td>\n","      <td>67</td>\n","      <td>48</td>\n","      <td>12</td>\n","      <td>9</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Italy</td>\n","      <td>6</td>\n","      <td>34</td>\n","      <td>45</td>\n","      <td>43.0%</td>\n","      <td>7.5%</td>\n","      <td>110</td>\n","      <td>2</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>2</td>\n","      <td>18</td>\n","      <td>7</td>\n","      <td>20</td>\n","      <td>74.1%</td>\n","      <td>101</td>\n","      <td>89</td>\n","      <td>16</td>\n","      <td>16</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>Netherlands</td>\n","      <td>2</td>\n","      <td>12</td>\n","      <td>36</td>\n","      <td>25.0%</td>\n","      <td>4.1%</td>\n","      <td>60</td>\n","      <td>2</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>0</td>\n","      <td>9</td>\n","      <td>5</td>\n","      <td>12</td>\n","      <td>70.6%</td>\n","      <td>35</td>\n","      <td>30</td>\n","      <td>3</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>Poland</td>\n","      <td>2</td>\n","      <td>15</td>\n","      <td>23</td>\n","      <td>39.4%</td>\n","      <td>5.2%</td>\n","      <td>48</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>0</td>\n","      <td>8</td>\n","      <td>3</td>\n","      <td>6</td>\n","      <td>66.7%</td>\n","      <td>48</td>\n","      <td>56</td>\n","      <td>3</td>\n","      <td>7</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>Portugal</td>\n","      <td>6</td>\n","      <td>22</td>\n","      <td>42</td>\n","      <td>34.3%</td>\n","      <td>9.3%</td>\n","      <td>82</td>\n","      <td>6</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>2</td>\n","      <td>11</td>\n","      <td>4</td>\n","      <td>10</td>\n","      <td>71.5%</td>\n","      <td>73</td>\n","      <td>90</td>\n","      <td>10</td>\n","      <td>12</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>Republic of Ireland</td>\n","      <td>1</td>\n","      <td>7</td>\n","      <td>12</td>\n","      <td>36.8%</td>\n","      <td>5.2%</td>\n","      <td>28</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>0</td>\n","      <td>23</td>\n","      <td>9</td>\n","      <td>17</td>\n","      <td>65.4%</td>\n","      <td>43</td>\n","      <td>51</td>\n","      <td>11</td>\n","      <td>6</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>Russia</td>\n","      <td>5</td>\n","      <td>9</td>\n","      <td>31</td>\n","      <td>22.5%</td>\n","      <td>12.5%</td>\n","      <td>59</td>\n","      <td>2</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>0</td>\n","      <td>8</td>\n","      <td>3</td>\n","      <td>10</td>\n","      <td>77.0%</td>\n","      <td>34</td>\n","      <td>43</td>\n","      <td>4</td>\n","      <td>6</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>Spain</td>\n","      <td>12</td>\n","      <td>42</td>\n","      <td>33</td>\n","      <td>55.9%</td>\n","      <td>16.0%</td>\n","      <td>100</td>\n","      <td>0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>5</td>\n","      <td>8</td>\n","      <td>1</td>\n","      <td>15</td>\n","      <td>93.8%</td>\n","      <td>102</td>\n","      <td>83</td>\n","      <td>19</td>\n","      <td>11</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>14</th>\n","      <td>Sweden</td>\n","      <td>5</td>\n","      <td>17</td>\n","      <td>19</td>\n","      <td>47.2%</td>\n","      <td>13.8%</td>\n","      <td>39</td>\n","      <td>3</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>12</td>\n","      <td>5</td>\n","      <td>8</td>\n","      <td>61.6%</td>\n","      <td>35</td>\n","      <td>51</td>\n","      <td>7</td>\n","      <td>7</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>15</th>\n","      <td>Ukraine</td>\n","      <td>2</td>\n","      <td>7</td>\n","      <td>26</td>\n","      <td>21.2%</td>\n","      <td>6.0%</td>\n","      <td>38</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>...</td>\n","      <td>0</td>\n","      <td>4</td>\n","      <td>4</td>\n","      <td>13</td>\n","      <td>76.5%</td>\n","      <td>48</td>\n","      <td>31</td>\n","      <td>4</td>\n","      <td>5</td>\n","      <td>0</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>16 rows × 32 columns</p>\n","</div>"],"text/plain":["                   Team  Goals  Shots on target  Shots off target  \\\n","0               Croatia      4               13                12   \n","1        Czech Republic      4               13                18   \n","2               Denmark      4               10                10   \n","3               England      5               11                18   \n","4                France      3               22                24   \n","5               Germany     10               32                32   \n","6                Greece      5                8                18   \n","7                 Italy      6               34                45   \n","8           Netherlands      2               12                36   \n","9                Poland      2               15                23   \n","10             Portugal      6               22                42   \n","11  Republic of Ireland      1                7                12   \n","12               Russia      5                9                31   \n","13                Spain     12               42                33   \n","14               Sweden      5               17                19   \n","15              Ukraine      2                7                26   \n","\n","   Shooting Accuracy % Goals-to-shots  Total shots (inc. Blocked)  \\\n","0              51.9%            16.0%                          32   \n","1              41.9%            12.9%                          39   \n","2              50.0%            20.0%                          27   \n","3              50.0%            17.2%                          40   \n","4              37.9%             6.5%                          65   \n","5              47.8%            15.6%                          80   \n","6              30.7%            19.2%                          32   \n","7              43.0%             7.5%                         110   \n","8              25.0%             4.1%                          60   \n","9              39.4%             5.2%                          48   \n","10             34.3%             9.3%                          82   \n","11             36.8%             5.2%                          28   \n","12             22.5%            12.5%                          59   \n","13             55.9%            16.0%                         100   \n","14             47.2%            13.8%                          39   \n","15             21.2%             6.0%                          38   \n","\n","    Hit Woodwork  Penalty goals  Penalties not scored    ...      \\\n","0              0              0                     0    ...       \n","1              0              0                     0    ...       \n","2              1              0                     0    ...       \n","3              0              0                     0    ...       \n","4              1              0                     0    ...       \n","5              2              1                     0    ...       \n","6              1              1                     1    ...       \n","7              2              0                     0    ...       \n","8              2              0                     0    ...       \n","9              0              0                     0    ...       \n","10             6              0                     0    ...       \n","11             0              0                     0    ...       \n","12             2              0                     0    ...       \n","13             0              1                     0    ...       \n","14             3              0                     0    ...       \n","15             0              0                     0    ...       \n","\n","    Clean Sheets  Blocks  Goals conceded Saves made  Saves-to-shots ratio  \\\n","0              0      10               3         13                 81.3%   \n","1              1      10               6          9                 60.1%   \n","2              1      10               5         10                 66.7%   \n","3              2      29               3         22                 88.1%   \n","4              1       7               5          6                 54.6%   \n","5              1      11               6         10                 62.6%   \n","6              1      23               7         13                 65.1%   \n","7              2      18               7         20                 74.1%   \n","8              0       9               5         12                 70.6%   \n","9              0       8               3          6                 66.7%   \n","10             2      11               4         10                 71.5%   \n","11             0      23               9         17                 65.4%   \n","12             0       8               3         10                 77.0%   \n","13             5       8               1         15                 93.8%   \n","14             1      12               5          8                 61.6%   \n","15             0       4               4         13                 76.5%   \n","\n","    Fouls Won  Fouls Conceded  Offsides  Yellow Cards  Red Cards  \n","0          41              62         2             9          0  \n","1          53              73         8             7          0  \n","2          25              38         8             4          0  \n","3          43              45         6             5          0  \n","4          36              51         5             6          0  \n","5          63              49        12             4          0  \n","6          67              48        12             9          1  \n","7         101              89        16            16          0  \n","8          35              30         3             5          0  \n","9          48              56         3             7          1  \n","10         73              90        10            12          0  \n","11         43              51        11             6          1  \n","12         34              43         4             6          0  \n","13        102              83        19            11          0  \n","14         35              51         7             7          0  \n","15         48              31         4             5          0  \n","\n","[16 rows x 32 columns]"]},"execution_count":260,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12.iloc[: , :-3]"]},{"cell_type":"markdown","metadata":{"id":"FF3B1C8001AC48F78DF5F9B74EB8BB30","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤14 找到英格兰(England)、意大利(Italy)和俄罗斯(Russia)的射正率(Shooting Accuracy)"]},{"cell_type":"code","execution_count":261,"metadata":{"collapsed":false,"id":"015C98A393904B02899979F2B8F182CE","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Team</th>\n","      <th>Shooting Accuracy</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>3</th>\n","      <td>England</td>\n","      <td>50.0%</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Italy</td>\n","      <td>43.0%</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>Russia</td>\n","      <td>22.5%</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["       Team Shooting Accuracy\n","3   England             50.0%\n","7     Italy             43.0%\n","12   Russia             22.5%"]},"execution_count":261,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","euro12.loc[euro12.Team.isin(['England', 'Italy', 'Russia']), ['Team','Shooting Accuracy']]"]},{"cell_type":"markdown","metadata":{"id":"E45B8E327C664DA08DEDB4175C898256","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"77CFCC73BCD943C288E74EC39B33E294","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习3-数据分组\n","## 探索酒类消费数据\n","![image description](https://cdn.kesci.com/images/lab_upload/1508342577428_72275.jpeg)"]},{"cell_type":"markdown","metadata":{"id":"8BC649FC843A43D3A980BD52256898C2","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"02A33F3106444A9EBD0C44CFCE22A958","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":262,"metadata":{"collapsed":false,"id":"94147E1320EC447891CFBDDC483887ED","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd"]},{"cell_type":"markdown","metadata":{"id":"3E67806E06FF45A38295F20E6F0E518C","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 从以下地址导入数据"]},{"cell_type":"code","execution_count":10,"metadata":{"collapsed":false,"id":"5BFF41EDF82B420D84E3C12E510F07A9","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path3 ='../input/pandas_exercise/pandas_exercise/exercise_data/drinks.csv'    #'drinks.csv'"]},{"cell_type":"markdown","metadata":{"id":"D7B050FD133C4E888B62A1BF5F98C5A5","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将数据框命名为drinks"]},{"cell_type":"code","execution_count":11,"metadata":{"collapsed":false,"id":"91D1A6E80D9E45E9AF2BB28F7347F644","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>country</th>\n","      <th>beer_servings</th>\n","      <th>spirit_servings</th>\n","      <th>wine_servings</th>\n","      <th>total_litres_of_pure_alcohol</th>\n","      <th>continent</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Afghanistan</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>0.0</td>\n","      <td>AS</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Albania</td>\n","      <td>89</td>\n","      <td>132</td>\n","      <td>54</td>\n","      <td>4.9</td>\n","      <td>EU</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Algeria</td>\n","      <td>25</td>\n","      <td>0</td>\n","      <td>14</td>\n","      <td>0.7</td>\n","      <td>AF</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>Andorra</td>\n","      <td>245</td>\n","      <td>138</td>\n","      <td>312</td>\n","      <td>12.4</td>\n","      <td>EU</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>Angola</td>\n","      <td>217</td>\n","      <td>57</td>\n","      <td>45</td>\n","      <td>5.9</td>\n","      <td>AF</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["       country  beer_servings  spirit_servings  wine_servings  \\\n","0  Afghanistan              0                0              0   \n","1      Albania             89              132             54   \n","2      Algeria             25                0             14   \n","3      Andorra            245              138            312   \n","4       Angola            217               57             45   \n","\n","   total_litres_of_pure_alcohol continent  \n","0                           0.0        AS  \n","1                           4.9        EU  \n","2                           0.7        AF  \n","3                          12.4        EU  \n","4                           5.9        AF  "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","drinks = pd.read_csv(path3)\n","drinks.head()"]},{"cell_type":"markdown","metadata":{"id":"7F81F2F626434CAB8523A34810A3B364","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 哪个大陆(continent)平均消耗的啤酒(beer)更多？"]},{"cell_type":"code","execution_count":12,"metadata":{"collapsed":false,"id":"AE1440261F794F07839668110CA3ECDA","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["continent\n","AF     61.471698\n","AS     37.045455\n","EU    193.777778\n","OC     89.687500\n","SA    175.083333\n","Name: beer_servings, dtype: float64"]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","drinks.groupby('continent').beer_servings.mean()"]},{"cell_type":"markdown","metadata":{"id":"15D6B9245935455B881D93188B76D460","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 打印出每个大陆(continent)的红酒消耗(wine_servings)的描述性统计值"]},{"cell_type":"code","execution_count":13,"metadata":{"collapsed":false,"id":"96617DDCCDC7466E8E743CA9B5533B85","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>count</th>\n","      <th>mean</th>\n","      <th>std</th>\n","      <th>min</th>\n","      <th>25%</th>\n","      <th>50%</th>\n","      <th>75%</th>\n","      <th>max</th>\n","    </tr>\n","    <tr>\n","      <th>continent</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>AF</th>\n","      <td>53.0</td>\n","      <td>16.264151</td>\n","      <td>38.846419</td>\n","      <td>0.0</td>\n","      <td>1.0</td>\n","      <td>2.0</td>\n","      <td>13.00</td>\n","      <td>233.0</td>\n","    </tr>\n","    <tr>\n","      <th>AS</th>\n","      <td>44.0</td>\n","      <td>9.068182</td>\n","      <td>21.667034</td>\n","      <td>0.0</td>\n","      <td>0.0</td>\n","      <td>1.0</td>\n","      <td>8.00</td>\n","      <td>123.0</td>\n","    </tr>\n","    <tr>\n","      <th>EU</th>\n","      <td>45.0</td>\n","      <td>142.222222</td>\n","      <td>97.421738</td>\n","      <td>0.0</td>\n","      <td>59.0</td>\n","      <td>128.0</td>\n","      <td>195.00</td>\n","      <td>370.0</td>\n","    </tr>\n","    <tr>\n","      <th>OC</th>\n","      <td>16.0</td>\n","      <td>35.625000</td>\n","      <td>64.555790</td>\n","      <td>0.0</td>\n","      <td>1.0</td>\n","      <td>8.5</td>\n","      <td>23.25</td>\n","      <td>212.0</td>\n","    </tr>\n","    <tr>\n","      <th>SA</th>\n","      <td>12.0</td>\n","      <td>62.416667</td>\n","      <td>88.620189</td>\n","      <td>1.0</td>\n","      <td>3.0</td>\n","      <td>12.0</td>\n","      <td>98.50</td>\n","      <td>221.0</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["           count        mean        std  min   25%    50%     75%    max\n","continent                                                               \n","AF          53.0   16.264151  38.846419  0.0   1.0    2.0   13.00  233.0\n","AS          44.0    9.068182  21.667034  0.0   0.0    1.0    8.00  123.0\n","EU          45.0  142.222222  97.421738  0.0  59.0  128.0  195.00  370.0\n","OC          16.0   35.625000  64.555790  0.0   1.0    8.5   23.25  212.0\n","SA          12.0   62.416667  88.620189  1.0   3.0   12.0   98.50  221.0"]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","drinks.groupby('continent').wine_servings.describe()"]},{"cell_type":"markdown","metadata":{"id":"ACF75BF8D80240D1810008833043DD5C","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 打印出每个大陆每种酒类别的消耗平均值"]},{"cell_type":"code","execution_count":15,"metadata":{"collapsed":false,"id":"092D2E7F45DE45F1861573BEA9FDC5E3","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>beer_servings</th>\n","      <th>spirit_servings</th>\n","      <th>wine_servings</th>\n","      <th>total_litres_of_pure_alcohol</th>\n","    </tr>\n","    <tr>\n","      <th>continent</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>AF</th>\n","      <td>61.471698</td>\n","      <td>16.339623</td>\n","      <td>16.264151</td>\n","      <td>3.007547</td>\n","    </tr>\n","    <tr>\n","      <th>AS</th>\n","      <td>37.045455</td>\n","      <td>60.840909</td>\n","      <td>9.068182</td>\n","      <td>2.170455</td>\n","    </tr>\n","    <tr>\n","      <th>EU</th>\n","      <td>193.777778</td>\n","      <td>132.555556</td>\n","      <td>142.222222</td>\n","      <td>8.617778</td>\n","    </tr>\n","    <tr>\n","      <th>OC</th>\n","      <td>89.687500</td>\n","      <td>58.437500</td>\n","      <td>35.625000</td>\n","      <td>3.381250</td>\n","    </tr>\n","    <tr>\n","      <th>SA</th>\n","      <td>175.083333</td>\n","      <td>114.750000</td>\n","      <td>62.416667</td>\n","      <td>6.308333</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["           beer_servings  spirit_servings  wine_servings  \\\n","continent                                                  \n","AF             61.471698        16.339623      16.264151   \n","AS             37.045455        60.840909       9.068182   \n","EU            193.777778       132.555556     142.222222   \n","OC             89.687500        58.437500      35.625000   \n","SA            175.083333       114.750000      62.416667   \n","\n","           total_litres_of_pure_alcohol  \n","continent                                \n","AF                             3.007547  \n","AS                             2.170455  \n","EU                             8.617778  \n","OC                             3.381250  \n","SA                             6.308333  "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","drinks.groupby('continent').mean()"]},{"cell_type":"markdown","metadata":{"id":"DA43F7A2E2A64B14B1B6A9303963237F","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 打印出每个大陆每种酒类别的消耗中位数"]},{"cell_type":"code","execution_count":268,"metadata":{"collapsed":false,"id":"DED8A2BF935E4C05894EAC4E015D4823","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>beer_servings</th>\n","      <th>spirit_servings</th>\n","      <th>wine_servings</th>\n","      <th>total_litres_of_pure_alcohol</th>\n","    </tr>\n","    <tr>\n","      <th>continent</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>AF</th>\n","      <td>32.0</td>\n","      <td>3.0</td>\n","      <td>2.0</td>\n","      <td>2.30</td>\n","    </tr>\n","    <tr>\n","      <th>AS</th>\n","      <td>17.5</td>\n","      <td>16.0</td>\n","      <td>1.0</td>\n","      <td>1.20</td>\n","    </tr>\n","    <tr>\n","      <th>EU</th>\n","      <td>219.0</td>\n","      <td>122.0</td>\n","      <td>128.0</td>\n","      <td>10.00</td>\n","    </tr>\n","    <tr>\n","      <th>OC</th>\n","      <td>52.5</td>\n","      <td>37.0</td>\n","      <td>8.5</td>\n","      <td>1.75</td>\n","    </tr>\n","    <tr>\n","      <th>SA</th>\n","      <td>162.5</td>\n","      <td>108.5</td>\n","      <td>12.0</td>\n","      <td>6.85</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["           beer_servings  spirit_servings  wine_servings  \\\n","continent                                                  \n","AF                  32.0              3.0            2.0   \n","AS                  17.5             16.0            1.0   \n","EU                 219.0            122.0          128.0   \n","OC                  52.5             37.0            8.5   \n","SA                 162.5            108.5           12.0   \n","\n","           total_litres_of_pure_alcohol  \n","continent                                \n","AF                                 2.30  \n","AS                                 1.20  \n","EU                                10.00  \n","OC                                 1.75  \n","SA                                 6.85  "]},"execution_count":268,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","drinks.groupby('continent').median()"]},{"cell_type":"markdown","metadata":{"id":"305BD2BFC20B43FE994324166EEB02FA","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 打印出每个大陆对spirit饮品消耗的平均值，最大值和最小值"]},{"cell_type":"code","execution_count":269,"metadata":{"collapsed":false,"id":"DE5B7DDE27F64D03B7B8B5596E424D8A","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>mean</th>\n","      <th>min</th>\n","      <th>max</th>\n","    </tr>\n","    <tr>\n","      <th>continent</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>AF</th>\n","      <td>16.339623</td>\n","      <td>0</td>\n","      <td>152</td>\n","    </tr>\n","    <tr>\n","      <th>AS</th>\n","      <td>60.840909</td>\n","      <td>0</td>\n","      <td>326</td>\n","    </tr>\n","    <tr>\n","      <th>EU</th>\n","      <td>132.555556</td>\n","      <td>0</td>\n","      <td>373</td>\n","    </tr>\n","    <tr>\n","      <th>OC</th>\n","      <td>58.437500</td>\n","      <td>0</td>\n","      <td>254</td>\n","    </tr>\n","    <tr>\n","      <th>SA</th>\n","      <td>114.750000</td>\n","      <td>25</td>\n","      <td>302</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["                 mean  min  max\n","continent                      \n","AF          16.339623    0  152\n","AS          60.840909    0  326\n","EU         132.555556    0  373\n","OC          58.437500    0  254\n","SA         114.750000   25  302"]},"execution_count":269,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","drinks.groupby('continent').spirit_servings.agg(['mean', 'min', 'max'])"]},{"cell_type":"markdown","metadata":{"id":"B1B8F46F84EC43758727ADDD2F9B12C9","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习4-Apply函数\n","## 探索1960 - 2014 美国犯罪数据\n","![image description](https://cdn.kesci.com/images/lab_upload/1508342597565_76025.jpeg)"]},{"cell_type":"markdown","metadata":{"id":"AD9F04550A8342FC8FEFB09919CEF7E2","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"62C5BF1BFF6741CF8A6697F103911D43","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":16,"metadata":{"collapsed":false,"id":"B2C0CD7655EA440BAA73922FB2BC4DC0","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import numpy as np\n","import pandas as pd"]},{"cell_type":"markdown","metadata":{"id":"1B1196743C2B4CBB88FA21F9D523F83B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 从以下地址导入数据集"]},{"cell_type":"code","execution_count":27,"metadata":{"collapsed":false,"id":"C89AA408D29E47FEBAE5CFABA8B1C9CB","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path4 = '../input/pandas_exercise/pandas_exercise/exercise_data/US_Crime_Rates_1960_2014.csv'    # \"US_Crime_Rates_1960_2014.csv\""]},{"cell_type":"markdown","metadata":{"id":"D2EF6ADD3344480C88C78293EC99A74A","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将数据框命名为crime"]},{"cell_type":"code","execution_count":28,"metadata":{"collapsed":false,"id":"A070C9CD3B924A1C8B3770E797AAE0C5","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Year</th>\n","      <th>Population</th>\n","      <th>Total</th>\n","      <th>Violent</th>\n","      <th>Property</th>\n","      <th>Murder</th>\n","      <th>Forcible_Rape</th>\n","      <th>Robbery</th>\n","      <th>Aggravated_assault</th>\n","      <th>Burglary</th>\n","      <th>Larceny_Theft</th>\n","      <th>Vehicle_Theft</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1960</td>\n","      <td>179323175</td>\n","      <td>3384200</td>\n","      <td>288460</td>\n","      <td>3095700</td>\n","      <td>9110</td>\n","      <td>17190</td>\n","      <td>107840</td>\n","      <td>154320</td>\n","      <td>912100</td>\n","      <td>1855400</td>\n","      <td>328200</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>1961</td>\n","      <td>182992000</td>\n","      <td>3488000</td>\n","      <td>289390</td>\n","      <td>3198600</td>\n","      <td>8740</td>\n","      <td>17220</td>\n","      <td>106670</td>\n","      <td>156760</td>\n","      <td>949600</td>\n","      <td>1913000</td>\n","      <td>336000</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>1962</td>\n","      <td>185771000</td>\n","      <td>3752200</td>\n","      <td>301510</td>\n","      <td>3450700</td>\n","      <td>8530</td>\n","      <td>17550</td>\n","      <td>110860</td>\n","      <td>164570</td>\n","      <td>994300</td>\n","      <td>2089600</td>\n","      <td>366800</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>1963</td>\n","      <td>188483000</td>\n","      <td>4109500</td>\n","      <td>316970</td>\n","      <td>3792500</td>\n","      <td>8640</td>\n","      <td>17650</td>\n","      <td>116470</td>\n","      <td>174210</td>\n","      <td>1086400</td>\n","      <td>2297800</td>\n","      <td>408300</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>1964</td>\n","      <td>191141000</td>\n","      <td>4564600</td>\n","      <td>364220</td>\n","      <td>4200400</td>\n","      <td>9360</td>\n","      <td>21420</td>\n","      <td>130390</td>\n","      <td>203050</td>\n","      <td>1213200</td>\n","      <td>2514400</td>\n","      <td>472800</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   Year  Population    Total  Violent  Property  Murder  Forcible_Rape  \\\n","0  1960   179323175  3384200   288460   3095700    9110          17190   \n","1  1961   182992000  3488000   289390   3198600    8740          17220   \n","2  1962   185771000  3752200   301510   3450700    8530          17550   \n","3  1963   188483000  4109500   316970   3792500    8640          17650   \n","4  1964   191141000  4564600   364220   4200400    9360          21420   \n","\n","   Robbery  Aggravated_assault  Burglary  Larceny_Theft  Vehicle_Theft  \n","0   107840              154320    912100        1855400         328200  \n","1   106670              156760    949600        1913000         336000  \n","2   110860              164570    994300        2089600         366800  \n","3   116470              174210   1086400        2297800         408300  \n","4   130390              203050   1213200        2514400         472800  "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","crime = pd.read_csv(path4)\n","crime.head()"]},{"cell_type":"markdown","metadata":{"id":"59843F4F0B7343D5AB7645E6E45D7A34","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 每一列(column)的数据类型是什么样的？"]},{"cell_type":"code","execution_count":29,"metadata":{"collapsed":false,"id":"249F0DC481BA4F27A3B8B0A568CC8BDF","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["<class 'pandas.core.frame.DataFrame'>\n","RangeIndex: 55 entries, 0 to 54\n","Data columns (total 12 columns):\n","Year                  55 non-null int64\n","Population            55 non-null int64\n","Total                 55 non-null int64\n","Violent               55 non-null int64\n","Property              55 non-null int64\n","Murder                55 non-null int64\n","Forcible_Rape         55 non-null int64\n","Robbery               55 non-null int64\n","Aggravated_assault    55 non-null int64\n","Burglary              55 non-null int64\n","Larceny_Theft         55 non-null int64\n","Vehicle_Theft         55 non-null int64\n","dtypes: int64(12)\n","memory usage: 5.2 KB\n"]}],"source":["# 运行以下代码\n","crime.info()"]},{"cell_type":"markdown","metadata":{"id":"3D23C3403EF04A8AA9755F4E6B6A2755","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["*注意到了吗，Year的数据类型为 ```int64```，但是pandas有一个不同的数据类型去处理时间序列(time series)，我们现在来看看。*"]},{"cell_type":"markdown","metadata":{"id":"A775282CD76D4B2BAC818AB9E5B7763A","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 将Year的数据类型转换为 ```datetime64```"]},{"cell_type":"code","execution_count":30,"metadata":{"collapsed":false,"id":"C2078123F13F4363845C278A07DF1CDB","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["<class 'pandas.core.frame.DataFrame'>\n","RangeIndex: 55 entries, 0 to 54\n","Data columns (total 12 columns):\n","Year                  55 non-null datetime64[ns]\n","Population            55 non-null int64\n","Total                 55 non-null int64\n","Violent               55 non-null int64\n","Property              55 non-null int64\n","Murder                55 non-null int64\n","Forcible_Rape         55 non-null int64\n","Robbery               55 non-null int64\n","Aggravated_assault    55 non-null int64\n","Burglary              55 non-null int64\n","Larceny_Theft         55 non-null int64\n","Vehicle_Theft         55 non-null int64\n","dtypes: datetime64[ns](1), int64(11)\n","memory usage: 5.2 KB\n"]}],"source":["# 运行以下代码\n","crime.Year = pd.to_datetime(crime.Year, format='%Y')\n","crime.info()"]},{"cell_type":"markdown","metadata":{"id":"FAEFF8BE60B840C68EF78D362F783C62","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 将列Year设置为数据框的索引"]},{"cell_type":"code","execution_count":31,"metadata":{"collapsed":false,"id":"1F4D15E8F506408082843D864886B807","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Population</th>\n","      <th>Total</th>\n","      <th>Violent</th>\n","      <th>Property</th>\n","      <th>Murder</th>\n","      <th>Forcible_Rape</th>\n","      <th>Robbery</th>\n","      <th>Aggravated_assault</th>\n","      <th>Burglary</th>\n","      <th>Larceny_Theft</th>\n","      <th>Vehicle_Theft</th>\n","    </tr>\n","    <tr>\n","      <th>Year</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1960-01-01</th>\n","      <td>179323175</td>\n","      <td>3384200</td>\n","      <td>288460</td>\n","      <td>3095700</td>\n","      <td>9110</td>\n","      <td>17190</td>\n","      <td>107840</td>\n","      <td>154320</td>\n","      <td>912100</td>\n","      <td>1855400</td>\n","      <td>328200</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-01</th>\n","      <td>182992000</td>\n","      <td>3488000</td>\n","      <td>289390</td>\n","      <td>3198600</td>\n","      <td>8740</td>\n","      <td>17220</td>\n","      <td>106670</td>\n","      <td>156760</td>\n","      <td>949600</td>\n","      <td>1913000</td>\n","      <td>336000</td>\n","    </tr>\n","    <tr>\n","      <th>1962-01-01</th>\n","      <td>185771000</td>\n","      <td>3752200</td>\n","      <td>301510</td>\n","      <td>3450700</td>\n","      <td>8530</td>\n","      <td>17550</td>\n","      <td>110860</td>\n","      <td>164570</td>\n","      <td>994300</td>\n","      <td>2089600</td>\n","      <td>366800</td>\n","    </tr>\n","    <tr>\n","      <th>1963-01-01</th>\n","      <td>188483000</td>\n","      <td>4109500</td>\n","      <td>316970</td>\n","      <td>3792500</td>\n","      <td>8640</td>\n","      <td>17650</td>\n","      <td>116470</td>\n","      <td>174210</td>\n","      <td>1086400</td>\n","      <td>2297800</td>\n","      <td>408300</td>\n","    </tr>\n","    <tr>\n","      <th>1964-01-01</th>\n","      <td>191141000</td>\n","      <td>4564600</td>\n","      <td>364220</td>\n","      <td>4200400</td>\n","      <td>9360</td>\n","      <td>21420</td>\n","      <td>130390</td>\n","      <td>203050</td>\n","      <td>1213200</td>\n","      <td>2514400</td>\n","      <td>472800</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["            Population    Total  Violent  Property  Murder  Forcible_Rape  \\\n","Year                                                                        \n","1960-01-01   179323175  3384200   288460   3095700    9110          17190   \n","1961-01-01   182992000  3488000   289390   3198600    8740          17220   \n","1962-01-01   185771000  3752200   301510   3450700    8530          17550   \n","1963-01-01   188483000  4109500   316970   3792500    8640          17650   \n","1964-01-01   191141000  4564600   364220   4200400    9360          21420   \n","\n","            Robbery  Aggravated_assault  Burglary  Larceny_Theft  \\\n","Year                                                               \n","1960-01-01   107840              154320    912100        1855400   \n","1961-01-01   106670              156760    949600        1913000   \n","1962-01-01   110860              164570    994300        2089600   \n","1963-01-01   116470              174210   1086400        2297800   \n","1964-01-01   130390              203050   1213200        2514400   \n","\n","            Vehicle_Theft  \n","Year                       \n","1960-01-01         328200  \n","1961-01-01         336000  \n","1962-01-01         366800  \n","1963-01-01         408300  \n","1964-01-01         472800  "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","crime = crime.set_index('Year', drop = True)\n","crime.head()"]},{"cell_type":"markdown","metadata":{"id":"8ED9043146534B0484DBBDDA859A5CEC","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 删除名为Total的列"]},{"cell_type":"code","execution_count":32,"metadata":{"collapsed":false,"id":"E1AE7D9EACE94003BDB548358F835CB1","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Population</th>\n","      <th>Violent</th>\n","      <th>Property</th>\n","      <th>Murder</th>\n","      <th>Forcible_Rape</th>\n","      <th>Robbery</th>\n","      <th>Aggravated_assault</th>\n","      <th>Burglary</th>\n","      <th>Larceny_Theft</th>\n","      <th>Vehicle_Theft</th>\n","    </tr>\n","    <tr>\n","      <th>Year</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1960-01-01</th>\n","      <td>179323175</td>\n","      <td>288460</td>\n","      <td>3095700</td>\n","      <td>9110</td>\n","      <td>17190</td>\n","      <td>107840</td>\n","      <td>154320</td>\n","      <td>912100</td>\n","      <td>1855400</td>\n","      <td>328200</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-01</th>\n","      <td>182992000</td>\n","      <td>289390</td>\n","      <td>3198600</td>\n","      <td>8740</td>\n","      <td>17220</td>\n","      <td>106670</td>\n","      <td>156760</td>\n","      <td>949600</td>\n","      <td>1913000</td>\n","      <td>336000</td>\n","    </tr>\n","    <tr>\n","      <th>1962-01-01</th>\n","      <td>185771000</td>\n","      <td>301510</td>\n","      <td>3450700</td>\n","      <td>8530</td>\n","      <td>17550</td>\n","      <td>110860</td>\n","      <td>164570</td>\n","      <td>994300</td>\n","      <td>2089600</td>\n","      <td>366800</td>\n","    </tr>\n","    <tr>\n","      <th>1963-01-01</th>\n","      <td>188483000</td>\n","      <td>316970</td>\n","      <td>3792500</td>\n","      <td>8640</td>\n","      <td>17650</td>\n","      <td>116470</td>\n","      <td>174210</td>\n","      <td>1086400</td>\n","      <td>2297800</td>\n","      <td>408300</td>\n","    </tr>\n","    <tr>\n","      <th>1964-01-01</th>\n","      <td>191141000</td>\n","      <td>364220</td>\n","      <td>4200400</td>\n","      <td>9360</td>\n","      <td>21420</td>\n","      <td>130390</td>\n","      <td>203050</td>\n","      <td>1213200</td>\n","      <td>2514400</td>\n","      <td>472800</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["            Population  Violent  Property  Murder  Forcible_Rape  Robbery  \\\n","Year                                                                        \n","1960-01-01   179323175   288460   3095700    9110          17190   107840   \n","1961-01-01   182992000   289390   3198600    8740          17220   106670   \n","1962-01-01   185771000   301510   3450700    8530          17550   110860   \n","1963-01-01   188483000   316970   3792500    8640          17650   116470   \n","1964-01-01   191141000   364220   4200400    9360          21420   130390   \n","\n","            Aggravated_assault  Burglary  Larceny_Theft  Vehicle_Theft  \n","Year                                                                    \n","1960-01-01              154320    912100        1855400         328200  \n","1961-01-01              156760    949600        1913000         336000  \n","1962-01-01              164570    994300        2089600         366800  \n","1963-01-01              174210   1086400        2297800         408300  \n","1964-01-01              203050   1213200        2514400         472800  "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","del crime['Total']\n","crime.head()"]},{"cell_type":"code","execution_count":33,"metadata":{"collapsed":false,"id":"CB40284F44D14047BECD12DF7E38EADE","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Population</th>\n","      <th>Violent</th>\n","      <th>Property</th>\n","      <th>Murder</th>\n","      <th>Forcible_Rape</th>\n","      <th>Robbery</th>\n","      <th>Aggravated_assault</th>\n","      <th>Burglary</th>\n","      <th>Larceny_Theft</th>\n","      <th>Vehicle_Theft</th>\n","    </tr>\n","    <tr>\n","      <th>Year</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1960-01-01</th>\n","      <td>1915053175</td>\n","      <td>4134930</td>\n","      <td>45160900</td>\n","      <td>106180</td>\n","      <td>236720</td>\n","      <td>1633510</td>\n","      <td>2158520</td>\n","      <td>13321100</td>\n","      <td>26547700</td>\n","      <td>5292100</td>\n","    </tr>\n","    <tr>\n","      <th>1970-01-01</th>\n","      <td>2121193298</td>\n","      <td>9607930</td>\n","      <td>91383800</td>\n","      <td>192230</td>\n","      <td>554570</td>\n","      <td>4159020</td>\n","      <td>4702120</td>\n","      <td>28486000</td>\n","      <td>53157800</td>\n","      <td>9739900</td>\n","    </tr>\n","    <tr>\n","      <th>1980-01-01</th>\n","      <td>2371370069</td>\n","      <td>14074328</td>\n","      <td>117048900</td>\n","      <td>206439</td>\n","      <td>865639</td>\n","      <td>5383109</td>\n","      <td>7619130</td>\n","      <td>33073494</td>\n","      <td>72040253</td>\n","      <td>11935411</td>\n","    </tr>\n","    <tr>\n","      <th>1990-01-01</th>\n","      <td>2612825258</td>\n","      <td>17527048</td>\n","      <td>119053499</td>\n","      <td>211664</td>\n","      <td>998827</td>\n","      <td>5748930</td>\n","      <td>10568963</td>\n","      <td>26750015</td>\n","      <td>77679366</td>\n","      <td>14624418</td>\n","    </tr>\n","    <tr>\n","      <th>2000-01-01</th>\n","      <td>2947969117</td>\n","      <td>13968056</td>\n","      <td>100944369</td>\n","      <td>163068</td>\n","      <td>922499</td>\n","      <td>4230366</td>\n","      <td>8652124</td>\n","      <td>21565176</td>\n","      <td>67970291</td>\n","      <td>11412834</td>\n","    </tr>\n","    <tr>\n","      <th>2010-01-01</th>\n","      <td>1570146307</td>\n","      <td>6072017</td>\n","      <td>44095950</td>\n","      <td>72867</td>\n","      <td>421059</td>\n","      <td>1749809</td>\n","      <td>3764142</td>\n","      <td>10125170</td>\n","      <td>30401698</td>\n","      <td>3569080</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["            Population   Violent   Property  Murder  Forcible_Rape  Robbery  \\\n","Year                                                                          \n","1960-01-01  1915053175   4134930   45160900  106180         236720  1633510   \n","1970-01-01  2121193298   9607930   91383800  192230         554570  4159020   \n","1980-01-01  2371370069  14074328  117048900  206439         865639  5383109   \n","1990-01-01  2612825258  17527048  119053499  211664         998827  5748930   \n","2000-01-01  2947969117  13968056  100944369  163068         922499  4230366   \n","2010-01-01  1570146307   6072017   44095950   72867         421059  1749809   \n","\n","            Aggravated_assault  Burglary  Larceny_Theft  Vehicle_Theft  \n","Year                                                                    \n","1960-01-01             2158520  13321100       26547700        5292100  \n","1970-01-01             4702120  28486000       53157800        9739900  \n","1980-01-01             7619130  33073494       72040253       11935411  \n","1990-01-01            10568963  26750015       77679366       14624418  \n","2000-01-01             8652124  21565176       67970291       11412834  \n","2010-01-01             3764142  10125170       30401698        3569080  "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["crime.resample('10AS').sum()"]},{"cell_type":"markdown","metadata":{"id":"340AFD9DA23C4B4A92A202F630B25464","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 按照Year对数据框进行分组并求和 \n","*注意Population这一列，若直接对其求和，是不正确的**"]},{"cell_type":"code","execution_count":34,"metadata":{"collapsed":false,"id":"C8CBD7DEE49242EE988831AAEBB3EEFC","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Population</th>\n","      <th>Violent</th>\n","      <th>Property</th>\n","      <th>Murder</th>\n","      <th>Forcible_Rape</th>\n","      <th>Robbery</th>\n","      <th>Aggravated_assault</th>\n","      <th>Burglary</th>\n","      <th>Larceny_Theft</th>\n","      <th>Vehicle_Theft</th>\n","    </tr>\n","    <tr>\n","      <th>Year</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1960-01-01</th>\n","      <td>201385000</td>\n","      <td>4134930</td>\n","      <td>45160900</td>\n","      <td>106180</td>\n","      <td>236720</td>\n","      <td>1633510</td>\n","      <td>2158520</td>\n","      <td>13321100</td>\n","      <td>26547700</td>\n","      <td>5292100</td>\n","    </tr>\n","    <tr>\n","      <th>1970-01-01</th>\n","      <td>220099000</td>\n","      <td>9607930</td>\n","      <td>91383800</td>\n","      <td>192230</td>\n","      <td>554570</td>\n","      <td>4159020</td>\n","      <td>4702120</td>\n","      <td>28486000</td>\n","      <td>53157800</td>\n","      <td>9739900</td>\n","    </tr>\n","    <tr>\n","      <th>1980-01-01</th>\n","      <td>248239000</td>\n","      <td>14074328</td>\n","      <td>117048900</td>\n","      <td>206439</td>\n","      <td>865639</td>\n","      <td>5383109</td>\n","      <td>7619130</td>\n","      <td>33073494</td>\n","      <td>72040253</td>\n","      <td>11935411</td>\n","    </tr>\n","    <tr>\n","      <th>1990-01-01</th>\n","      <td>272690813</td>\n","      <td>17527048</td>\n","      <td>119053499</td>\n","      <td>211664</td>\n","      <td>998827</td>\n","      <td>5748930</td>\n","      <td>10568963</td>\n","      <td>26750015</td>\n","      <td>77679366</td>\n","      <td>14624418</td>\n","    </tr>\n","    <tr>\n","      <th>2000-01-01</th>\n","      <td>307006550</td>\n","      <td>13968056</td>\n","      <td>100944369</td>\n","      <td>163068</td>\n","      <td>922499</td>\n","      <td>4230366</td>\n","      <td>8652124</td>\n","      <td>21565176</td>\n","      <td>67970291</td>\n","      <td>11412834</td>\n","    </tr>\n","    <tr>\n","      <th>2010-01-01</th>\n","      <td>318857056</td>\n","      <td>6072017</td>\n","      <td>44095950</td>\n","      <td>72867</td>\n","      <td>421059</td>\n","      <td>1749809</td>\n","      <td>3764142</td>\n","      <td>10125170</td>\n","      <td>30401698</td>\n","      <td>3569080</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["            Population   Violent   Property  Murder  Forcible_Rape  Robbery  \\\n","Year                                                                          \n","1960-01-01   201385000   4134930   45160900  106180         236720  1633510   \n","1970-01-01   220099000   9607930   91383800  192230         554570  4159020   \n","1980-01-01   248239000  14074328  117048900  206439         865639  5383109   \n","1990-01-01   272690813  17527048  119053499  211664         998827  5748930   \n","2000-01-01   307006550  13968056  100944369  163068         922499  4230366   \n","2010-01-01   318857056   6072017   44095950   72867         421059  1749809   \n","\n","            Aggravated_assault  Burglary  Larceny_Theft  Vehicle_Theft  \n","Year                                                                    \n","1960-01-01             2158520  13321100       26547700        5292100  \n","1970-01-01             4702120  28486000       53157800        9739900  \n","1980-01-01             7619130  33073494       72040253       11935411  \n","1990-01-01            10568963  26750015       77679366       14624418  \n","2000-01-01             8652124  21565176       67970291       11412834  \n","2010-01-01             3764142  10125170       30401698        3569080  "]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 更多关于 .resample 的介绍\n","# (https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.resample.html)\n","# 更多关于 Offset Aliases的介绍 \n","# (http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases)\n","# 运行以下代码\n","crimes = crime.resample('10AS').sum() # resample a time series per decades\n","\n","\n","# 用resample去得到“Population”列的最大值\n","population = crime['Population'].resample('10AS').max()\n","\n","# 更新 \"Population\" \n","crimes['Population'] = population\n","\n","crimes"]},{"cell_type":"markdown","metadata":{"id":"8C1917E7819947EBB3BBC6FE4756296B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤9 何时是美国历史上生存最危险的年代？"]},{"cell_type":"code","execution_count":279,"metadata":{"collapsed":false,"id":"8F422A76F60E4E0F8A44D7D95A40AD8D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["Population           2014-01-01\n","Violent              1992-01-01\n","Property             1991-01-01\n","Murder               1991-01-01\n","Forcible_Rape        1992-01-01\n","Robbery              1991-01-01\n","Aggravated_assault   1993-01-01\n","Burglary             1980-01-01\n","Larceny_Theft        1991-01-01\n","Vehicle_Theft        1991-01-01\n","dtype: datetime64[ns]"]},"execution_count":279,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","crime.idxmax(0)"]},{"cell_type":"markdown","metadata":{"id":"932F2BD181B24D9893A13954EF98CB0A","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"5233896C64E441CBB5A905347BAE4552","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习5-合并\n","## 探索虚拟姓名数据"]},{"cell_type":"markdown","metadata":{"id":"9E601110A7D640C1A5436D00B85E546A","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"DAC8DC8ED3CC43C98269B6B80944633E","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":280,"metadata":{"collapsed":false,"id":"84D984E03FCB49BC90F83CED0365CC43","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import numpy as np\n","import pandas as pd"]},{"cell_type":"markdown","metadata":{"id":"13A34D69481A41A481C1343BCF294F85","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 按照如下的元数据内容创建数据框"]},{"cell_type":"code","execution_count":281,"metadata":{"collapsed":false,"id":"DC623E20AC794D71B7F113A6E961830C","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","raw_data_1 = {\n","        'subject_id': ['1', '2', '3', '4', '5'],\n","        'first_name': ['Alex', 'Amy', 'Allen', 'Alice', 'Ayoung'], \n","        'last_name': ['Anderson', 'Ackerman', 'Ali', 'Aoni', 'Atiches']}\n","\n","raw_data_2 = {\n","        'subject_id': ['4', '5', '6', '7', '8'],\n","        'first_name': ['Billy', 'Brian', 'Bran', 'Bryce', 'Betty'], \n","        'last_name': ['Bonder', 'Black', 'Balwner', 'Brice', 'Btisan']}\n","\n","raw_data_3 = {\n","        'subject_id': ['1', '2', '3', '4', '5', '7', '8', '9', '10', '11'],\n","        'test_id': [51, 15, 15, 61, 16, 14, 15, 1, 61, 16]}"]},{"cell_type":"markdown","metadata":{"id":"73EB083610EB4D0EB42210E29FF89708","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将上述的数据框分别命名为```data1, data2, data3```"]},{"cell_type":"code","execution_count":282,"metadata":{"collapsed":false,"id":"37509B2B90434B0A8823C29EE17AFB88","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","data1 = pd.DataFrame(raw_data_1, columns = ['subject_id', 'first_name', 'last_name'])\n","data2 = pd.DataFrame(raw_data_2, columns = ['subject_id', 'first_name', 'last_name'])\n","data3 = pd.DataFrame(raw_data_3, columns = ['subject_id','test_id'])"]},{"cell_type":"markdown","metadata":{"id":"9FA3DB0723724BAC86D35E1426B67DD7","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 将```data1```和```data2```两个数据框按照行的维度进行合并，命名为```all_data```"]},{"cell_type":"code","execution_count":283,"metadata":{"collapsed":false,"id":"DBDA1703967B490988CE69EE34596892","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>subject_id</th>\n","      <th>first_name</th>\n","      <th>last_name</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1</td>\n","      <td>Alex</td>\n","      <td>Anderson</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2</td>\n","      <td>Amy</td>\n","      <td>Ackerman</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>3</td>\n","      <td>Allen</td>\n","      <td>Ali</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4</td>\n","      <td>Alice</td>\n","      <td>Aoni</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5</td>\n","      <td>Ayoung</td>\n","      <td>Atiches</td>\n","    </tr>\n","    <tr>\n","      <th>0</th>\n","      <td>4</td>\n","      <td>Billy</td>\n","      <td>Bonder</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>5</td>\n","      <td>Brian</td>\n","      <td>Black</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>6</td>\n","      <td>Bran</td>\n","      <td>Balwner</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>7</td>\n","      <td>Bryce</td>\n","      <td>Brice</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>8</td>\n","      <td>Betty</td>\n","      <td>Btisan</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  subject_id first_name last_name\n","0          1       Alex  Anderson\n","1          2        Amy  Ackerman\n","2          3      Allen       Ali\n","3          4      Alice      Aoni\n","4          5     Ayoung   Atiches\n","0          4      Billy    Bonder\n","1          5      Brian     Black\n","2          6       Bran   Balwner\n","3          7      Bryce     Brice\n","4          8      Betty    Btisan"]},"execution_count":283,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","all_data = pd.concat([data1, data2])\n","all_data"]},{"cell_type":"markdown","metadata":{"id":"5EB108A7A79B47178C022967727EA8A5","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 将```data1```和```data2```两个数据框按照列的维度进行合并，命名为```all_data_col```"]},{"cell_type":"code","execution_count":284,"metadata":{"collapsed":false,"id":"A218C0590E624E0F91E1ABE910A69651","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>subject_id</th>\n","      <th>first_name</th>\n","      <th>last_name</th>\n","      <th>subject_id</th>\n","      <th>first_name</th>\n","      <th>last_name</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1</td>\n","      <td>Alex</td>\n","      <td>Anderson</td>\n","      <td>4</td>\n","      <td>Billy</td>\n","      <td>Bonder</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2</td>\n","      <td>Amy</td>\n","      <td>Ackerman</td>\n","      <td>5</td>\n","      <td>Brian</td>\n","      <td>Black</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>3</td>\n","      <td>Allen</td>\n","      <td>Ali</td>\n","      <td>6</td>\n","      <td>Bran</td>\n","      <td>Balwner</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4</td>\n","      <td>Alice</td>\n","      <td>Aoni</td>\n","      <td>7</td>\n","      <td>Bryce</td>\n","      <td>Brice</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5</td>\n","      <td>Ayoung</td>\n","      <td>Atiches</td>\n","      <td>8</td>\n","      <td>Betty</td>\n","      <td>Btisan</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  subject_id first_name last_name subject_id first_name last_name\n","0          1       Alex  Anderson          4      Billy    Bonder\n","1          2        Amy  Ackerman          5      Brian     Black\n","2          3      Allen       Ali          6       Bran   Balwner\n","3          4      Alice      Aoni          7      Bryce     Brice\n","4          5     Ayoung   Atiches          8      Betty    Btisan"]},"execution_count":284,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","all_data_col = pd.concat([data1, data2], axis = 1)\n","all_data_col"]},{"cell_type":"markdown","metadata":{"id":"0875A9C6EACE4369BE344AF5600B2069","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 打印```data3```"]},{"cell_type":"code","execution_count":285,"metadata":{"collapsed":false,"id":"C130A9FEC2434AB0BF165CEDE820E2C0","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>subject_id</th>\n","      <th>test_id</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1</td>\n","      <td>51</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2</td>\n","      <td>15</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>3</td>\n","      <td>15</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4</td>\n","      <td>61</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5</td>\n","      <td>16</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>7</td>\n","      <td>14</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>8</td>\n","      <td>15</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>9</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>10</td>\n","      <td>61</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>11</td>\n","      <td>16</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  subject_id  test_id\n","0          1       51\n","1          2       15\n","2          3       15\n","3          4       61\n","4          5       16\n","5          7       14\n","6          8       15\n","7          9        1\n","8         10       61\n","9         11       16"]},"execution_count":285,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","data3"]},{"cell_type":"markdown","metadata":{"id":"1751D631ACF14EB483EACAA14E6580CE","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 按照```subject_id```的值对```all_data```和```data3```作合并"]},{"cell_type":"code","execution_count":286,"metadata":{"collapsed":false,"id":"DCDC1EA0F86F4922919083979C2694E6","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>subject_id</th>\n","      <th>first_name</th>\n","      <th>last_name</th>\n","      <th>test_id</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1</td>\n","      <td>Alex</td>\n","      <td>Anderson</td>\n","      <td>51</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2</td>\n","      <td>Amy</td>\n","      <td>Ackerman</td>\n","      <td>15</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>3</td>\n","      <td>Allen</td>\n","      <td>Ali</td>\n","      <td>15</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4</td>\n","      <td>Alice</td>\n","      <td>Aoni</td>\n","      <td>61</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>4</td>\n","      <td>Billy</td>\n","      <td>Bonder</td>\n","      <td>61</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>5</td>\n","      <td>Ayoung</td>\n","      <td>Atiches</td>\n","      <td>16</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>5</td>\n","      <td>Brian</td>\n","      <td>Black</td>\n","      <td>16</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>7</td>\n","      <td>Bryce</td>\n","      <td>Brice</td>\n","      <td>14</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>8</td>\n","      <td>Betty</td>\n","      <td>Btisan</td>\n","      <td>15</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  subject_id first_name last_name  test_id\n","0          1       Alex  Anderson       51\n","1          2        Amy  Ackerman       15\n","2          3      Allen       Ali       15\n","3          4      Alice      Aoni       61\n","4          4      Billy    Bonder       61\n","5          5     Ayoung   Atiches       16\n","6          5      Brian     Black       16\n","7          7      Bryce     Brice       14\n","8          8      Betty    Btisan       15"]},"execution_count":286,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pd.merge(all_data, data3, on='subject_id')"]},{"cell_type":"markdown","metadata":{"id":"4AB863D6797D47268ECA616A8617D2A1","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 对```data1```和```data2```按照```subject_id```作连接"]},{"cell_type":"code","execution_count":287,"metadata":{"collapsed":false,"id":"B930510D11A8451E82E0F46CBB2C4B51","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>subject_id</th>\n","      <th>first_name_x</th>\n","      <th>last_name_x</th>\n","      <th>first_name_y</th>\n","      <th>last_name_y</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>4</td>\n","      <td>Alice</td>\n","      <td>Aoni</td>\n","      <td>Billy</td>\n","      <td>Bonder</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>5</td>\n","      <td>Ayoung</td>\n","      <td>Atiches</td>\n","      <td>Brian</td>\n","      <td>Black</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  subject_id first_name_x last_name_x first_name_y last_name_y\n","0          4        Alice        Aoni        Billy      Bonder\n","1          5       Ayoung     Atiches        Brian       Black"]},"execution_count":287,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pd.merge(data1, data2, on='subject_id', how='inner')"]},{"cell_type":"markdown","metadata":{"id":"3318003C9E7540FE91B26E2F0A23496E","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤9 找到 ```data1``` 和 ```data2``` 合并之后的所有匹配结果"]},{"cell_type":"code","execution_count":288,"metadata":{"collapsed":false,"id":"78923103F7EA4F15AC5B425ACE7E7841","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>subject_id</th>\n","      <th>first_name_x</th>\n","      <th>last_name_x</th>\n","      <th>first_name_y</th>\n","      <th>last_name_y</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1</td>\n","      <td>Alex</td>\n","      <td>Anderson</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2</td>\n","      <td>Amy</td>\n","      <td>Ackerman</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>3</td>\n","      <td>Allen</td>\n","      <td>Ali</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4</td>\n","      <td>Alice</td>\n","      <td>Aoni</td>\n","      <td>Billy</td>\n","      <td>Bonder</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5</td>\n","      <td>Ayoung</td>\n","      <td>Atiches</td>\n","      <td>Brian</td>\n","      <td>Black</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>6</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>Bran</td>\n","      <td>Balwner</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>7</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>Bryce</td>\n","      <td>Brice</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>8</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>Betty</td>\n","      <td>Btisan</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  subject_id first_name_x last_name_x first_name_y last_name_y\n","0          1         Alex    Anderson          NaN         NaN\n","1          2          Amy    Ackerman          NaN         NaN\n","2          3        Allen         Ali          NaN         NaN\n","3          4        Alice        Aoni        Billy      Bonder\n","4          5       Ayoung     Atiches        Brian       Black\n","5          6          NaN         NaN         Bran     Balwner\n","6          7          NaN         NaN        Bryce       Brice\n","7          8          NaN         NaN        Betty      Btisan"]},"execution_count":288,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pd.merge(data1, data2, on='subject_id', how='outer')"]},{"cell_type":"markdown","metadata":{"id":"3CB1D681AC0E4C1FA6B2C36FF88E23CA","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"7ADCA629E84245F48BF4EA8DF34EFF80","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习6-统计\n","## 探索风速数据\n","![image description](https://cdn.kesci.com/images/lab_upload/1508342625686_71026.jpg)"]},{"cell_type":"markdown","metadata":{"id":"6C5C11BB3EF046FF81072CDD25A1EA6A","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"458E578A769B4E7D885C647542C11721","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":289,"metadata":{"collapsed":false,"id":"EA7660C2A82745578567CF16D0046852","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd\n","import datetime"]},{"cell_type":"markdown","metadata":{"id":"C702C6C2832541A2BF5D7EE2A50267E3","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 从以下地址导入数据"]},{"cell_type":"code","execution_count":290,"metadata":{"collapsed":false,"id":"B2A8698EA5E04F34B9D0AC47FCD7357D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["import pandas as pd"]},{"cell_type":"code","execution_count":35,"metadata":{"collapsed":false,"id":"786C047535064711B3119FC51953AD6C","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path6 = \"../input/pandas_exercise/pandas_exercise/exercise_data/wind.data\"  # wind.data"]},{"cell_type":"markdown","metadata":{"id":"148CFE15D4FE4997A65E45EFB22A18E1","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将数据作存储并且设置前三列为合适的索引"]},{"cell_type":"code","execution_count":292,"metadata":{"collapsed":false,"id":"9696BB0F0AD447E4AE2B6AACBC9F87A7","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["import datetime"]},{"cell_type":"code","execution_count":293,"metadata":{"collapsed":false,"id":"F1A0E8471BEF4F1794CF2EAFC6B0D719","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Yr_Mo_Dy</th>\n","      <th>RPT</th>\n","      <th>VAL</th>\n","      <th>ROS</th>\n","      <th>KIL</th>\n","      <th>SHA</th>\n","      <th>BIR</th>\n","      <th>DUB</th>\n","      <th>CLA</th>\n","      <th>MUL</th>\n","      <th>CLO</th>\n","      <th>BEL</th>\n","      <th>MAL</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>2061-01-01</td>\n","      <td>15.04</td>\n","      <td>14.96</td>\n","      <td>13.17</td>\n","      <td>9.29</td>\n","      <td>NaN</td>\n","      <td>9.87</td>\n","      <td>13.67</td>\n","      <td>10.25</td>\n","      <td>10.83</td>\n","      <td>12.58</td>\n","      <td>18.50</td>\n","      <td>15.04</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2061-01-02</td>\n","      <td>14.71</td>\n","      <td>NaN</td>\n","      <td>10.83</td>\n","      <td>6.50</td>\n","      <td>12.62</td>\n","      <td>7.67</td>\n","      <td>11.50</td>\n","      <td>10.04</td>\n","      <td>9.79</td>\n","      <td>9.67</td>\n","      <td>17.54</td>\n","      <td>13.83</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>2061-01-03</td>\n","      <td>18.50</td>\n","      <td>16.88</td>\n","      <td>12.33</td>\n","      <td>10.13</td>\n","      <td>11.17</td>\n","      <td>6.17</td>\n","      <td>11.25</td>\n","      <td>NaN</td>\n","      <td>8.50</td>\n","      <td>7.67</td>\n","      <td>12.75</td>\n","      <td>12.71</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>2061-01-04</td>\n","      <td>10.58</td>\n","      <td>6.63</td>\n","      <td>11.75</td>\n","      <td>4.58</td>\n","      <td>4.54</td>\n","      <td>2.88</td>\n","      <td>8.63</td>\n","      <td>1.79</td>\n","      <td>5.83</td>\n","      <td>5.88</td>\n","      <td>5.46</td>\n","      <td>10.88</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>2061-01-05</td>\n","      <td>13.33</td>\n","      <td>13.25</td>\n","      <td>11.42</td>\n","      <td>6.17</td>\n","      <td>10.71</td>\n","      <td>8.21</td>\n","      <td>11.92</td>\n","      <td>6.54</td>\n","      <td>10.92</td>\n","      <td>10.34</td>\n","      <td>12.92</td>\n","      <td>11.83</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["    Yr_Mo_Dy    RPT    VAL    ROS    KIL    SHA   BIR    DUB    CLA    MUL  \\\n","0 2061-01-01  15.04  14.96  13.17   9.29    NaN  9.87  13.67  10.25  10.83   \n","1 2061-01-02  14.71    NaN  10.83   6.50  12.62  7.67  11.50  10.04   9.79   \n","2 2061-01-03  18.50  16.88  12.33  10.13  11.17  6.17  11.25    NaN   8.50   \n","3 2061-01-04  10.58   6.63  11.75   4.58   4.54  2.88   8.63   1.79   5.83   \n","4 2061-01-05  13.33  13.25  11.42   6.17  10.71  8.21  11.92   6.54  10.92   \n","\n","     CLO    BEL    MAL  \n","0  12.58  18.50  15.04  \n","1   9.67  17.54  13.83  \n","2   7.67  12.75  12.71  \n","3   5.88   5.46  10.88  \n","4  10.34  12.92  11.83  "]},"execution_count":293,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","data = pd.read_table(path6, sep = \"\\s+\", parse_dates = [[0,1,2]]) \n","data.head()"]},{"cell_type":"markdown","metadata":{"id":"074311F181FC4137893026C6326BCBA8","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 2061年？我们真的有这一年的数据？创建一个函数并用它去修复这个bug"]},{"cell_type":"code","execution_count":294,"metadata":{"collapsed":false,"id":"49D8631CAF5942E5A8C73BA7C7CFBA9B","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Yr_Mo_Dy</th>\n","      <th>RPT</th>\n","      <th>VAL</th>\n","      <th>ROS</th>\n","      <th>KIL</th>\n","      <th>SHA</th>\n","      <th>BIR</th>\n","      <th>DUB</th>\n","      <th>CLA</th>\n","      <th>MUL</th>\n","      <th>CLO</th>\n","      <th>BEL</th>\n","      <th>MAL</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1961-01-01</td>\n","      <td>15.04</td>\n","      <td>14.96</td>\n","      <td>13.17</td>\n","      <td>9.29</td>\n","      <td>NaN</td>\n","      <td>9.87</td>\n","      <td>13.67</td>\n","      <td>10.25</td>\n","      <td>10.83</td>\n","      <td>12.58</td>\n","      <td>18.50</td>\n","      <td>15.04</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>1961-01-02</td>\n","      <td>14.71</td>\n","      <td>NaN</td>\n","      <td>10.83</td>\n","      <td>6.50</td>\n","      <td>12.62</td>\n","      <td>7.67</td>\n","      <td>11.50</td>\n","      <td>10.04</td>\n","      <td>9.79</td>\n","      <td>9.67</td>\n","      <td>17.54</td>\n","      <td>13.83</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>1961-01-03</td>\n","      <td>18.50</td>\n","      <td>16.88</td>\n","      <td>12.33</td>\n","      <td>10.13</td>\n","      <td>11.17</td>\n","      <td>6.17</td>\n","      <td>11.25</td>\n","      <td>NaN</td>\n","      <td>8.50</td>\n","      <td>7.67</td>\n","      <td>12.75</td>\n","      <td>12.71</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>1961-01-04</td>\n","      <td>10.58</td>\n","      <td>6.63</td>\n","      <td>11.75</td>\n","      <td>4.58</td>\n","      <td>4.54</td>\n","      <td>2.88</td>\n","      <td>8.63</td>\n","      <td>1.79</td>\n","      <td>5.83</td>\n","      <td>5.88</td>\n","      <td>5.46</td>\n","      <td>10.88</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>1961-01-05</td>\n","      <td>13.33</td>\n","      <td>13.25</td>\n","      <td>11.42</td>\n","      <td>6.17</td>\n","      <td>10.71</td>\n","      <td>8.21</td>\n","      <td>11.92</td>\n","      <td>6.54</td>\n","      <td>10.92</td>\n","      <td>10.34</td>\n","      <td>12.92</td>\n","      <td>11.83</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["     Yr_Mo_Dy    RPT    VAL    ROS    KIL    SHA   BIR    DUB    CLA    MUL  \\\n","0  1961-01-01  15.04  14.96  13.17   9.29    NaN  9.87  13.67  10.25  10.83   \n","1  1961-01-02  14.71    NaN  10.83   6.50  12.62  7.67  11.50  10.04   9.79   \n","2  1961-01-03  18.50  16.88  12.33  10.13  11.17  6.17  11.25    NaN   8.50   \n","3  1961-01-04  10.58   6.63  11.75   4.58   4.54  2.88   8.63   1.79   5.83   \n","4  1961-01-05  13.33  13.25  11.42   6.17  10.71  8.21  11.92   6.54  10.92   \n","\n","     CLO    BEL    MAL  \n","0  12.58  18.50  15.04  \n","1   9.67  17.54  13.83  \n","2   7.67  12.75  12.71  \n","3   5.88   5.46  10.88  \n","4  10.34  12.92  11.83  "]},"execution_count":294,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","def fix_century(x):\n","    year = x.year - 100 if x.year > 1989 else x.year\n","    return datetime.date(year, x.month, x.day)\n","\n","# apply the function fix_century on the column and replace the values to the right ones\n","data['Yr_Mo_Dy'] = data['Yr_Mo_Dy'].apply(fix_century)\n","\n","# data.info()\n","data.head()"]},{"cell_type":"markdown","metadata":{"id":"3EA3C1E362DF4B2C99B2521FE44B153E","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 将日期设为索引，注意数据类型，应该是```datetime64[ns]```"]},{"cell_type":"code","execution_count":295,"metadata":{"collapsed":false,"id":"956320E6458441B88F3EC41E3D2FC969","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>RPT</th>\n","      <th>VAL</th>\n","      <th>ROS</th>\n","      <th>KIL</th>\n","      <th>SHA</th>\n","      <th>BIR</th>\n","      <th>DUB</th>\n","      <th>CLA</th>\n","      <th>MUL</th>\n","      <th>CLO</th>\n","      <th>BEL</th>\n","      <th>MAL</th>\n","    </tr>\n","    <tr>\n","      <th>Yr_Mo_Dy</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1961-01-01</th>\n","      <td>15.04</td>\n","      <td>14.96</td>\n","      <td>13.17</td>\n","      <td>9.29</td>\n","      <td>NaN</td>\n","      <td>9.87</td>\n","      <td>13.67</td>\n","      <td>10.25</td>\n","      <td>10.83</td>\n","      <td>12.58</td>\n","      <td>18.50</td>\n","      <td>15.04</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-02</th>\n","      <td>14.71</td>\n","      <td>NaN</td>\n","      <td>10.83</td>\n","      <td>6.50</td>\n","      <td>12.62</td>\n","      <td>7.67</td>\n","      <td>11.50</td>\n","      <td>10.04</td>\n","      <td>9.79</td>\n","      <td>9.67</td>\n","      <td>17.54</td>\n","      <td>13.83</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-03</th>\n","      <td>18.50</td>\n","      <td>16.88</td>\n","      <td>12.33</td>\n","      <td>10.13</td>\n","      <td>11.17</td>\n","      <td>6.17</td>\n","      <td>11.25</td>\n","      <td>NaN</td>\n","      <td>8.50</td>\n","      <td>7.67</td>\n","      <td>12.75</td>\n","      <td>12.71</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-04</th>\n","      <td>10.58</td>\n","      <td>6.63</td>\n","      <td>11.75</td>\n","      <td>4.58</td>\n","      <td>4.54</td>\n","      <td>2.88</td>\n","      <td>8.63</td>\n","      <td>1.79</td>\n","      <td>5.83</td>\n","      <td>5.88</td>\n","      <td>5.46</td>\n","      <td>10.88</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-05</th>\n","      <td>13.33</td>\n","      <td>13.25</td>\n","      <td>11.42</td>\n","      <td>6.17</td>\n","      <td>10.71</td>\n","      <td>8.21</td>\n","      <td>11.92</td>\n","      <td>6.54</td>\n","      <td>10.92</td>\n","      <td>10.34</td>\n","      <td>12.92</td>\n","      <td>11.83</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["              RPT    VAL    ROS    KIL    SHA   BIR    DUB    CLA    MUL  \\\n","Yr_Mo_Dy                                                                   \n","1961-01-01  15.04  14.96  13.17   9.29    NaN  9.87  13.67  10.25  10.83   \n","1961-01-02  14.71    NaN  10.83   6.50  12.62  7.67  11.50  10.04   9.79   \n","1961-01-03  18.50  16.88  12.33  10.13  11.17  6.17  11.25    NaN   8.50   \n","1961-01-04  10.58   6.63  11.75   4.58   4.54  2.88   8.63   1.79   5.83   \n","1961-01-05  13.33  13.25  11.42   6.17  10.71  8.21  11.92   6.54  10.92   \n","\n","              CLO    BEL    MAL  \n","Yr_Mo_Dy                         \n","1961-01-01  12.58  18.50  15.04  \n","1961-01-02   9.67  17.54  13.83  \n","1961-01-03   7.67  12.75  12.71  \n","1961-01-04   5.88   5.46  10.88  \n","1961-01-05  10.34  12.92  11.83  "]},"execution_count":295,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","# transform Yr_Mo_Dy it to date type datetime64\n","data[\"Yr_Mo_Dy\"] = pd.to_datetime(data[\"Yr_Mo_Dy\"])\n","\n","# set 'Yr_Mo_Dy' as the index\n","data = data.set_index('Yr_Mo_Dy')\n","\n","data.head()\n","# data.info()"]},{"cell_type":"markdown","metadata":{"id":"FF077E03C440424A87922681D9785C33","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 对应每一个location，一共有多少数据值缺失"]},{"cell_type":"code","execution_count":296,"metadata":{"collapsed":false,"id":"D7594C147C6B45658E318DBCE721661D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["RPT    6\n","VAL    3\n","ROS    2\n","KIL    5\n","SHA    2\n","BIR    0\n","DUB    3\n","CLA    2\n","MUL    3\n","CLO    1\n","BEL    0\n","MAL    4\n","dtype: int64"]},"execution_count":296,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","data.isnull().sum()"]},{"cell_type":"markdown","metadata":{"id":"F39E9243FCBE41808EE760B0423F9393","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 对应每一个location，一共有多少完整的数据值"]},{"cell_type":"code","execution_count":297,"metadata":{"collapsed":false,"id":"F5502CF4D71D464282B4EC2EB8422436","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["RPT    6568\n","VAL    6571\n","ROS    6572\n","KIL    6569\n","SHA    6572\n","BIR    6574\n","DUB    6571\n","CLA    6572\n","MUL    6571\n","CLO    6573\n","BEL    6574\n","MAL    6570\n","dtype: int64"]},"execution_count":297,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","data.shape[0] - data.isnull().sum()"]},{"cell_type":"markdown","metadata":{"id":"BAACC52E1E7745CB8217D9284EC30701","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 对于全体数据，计算风速的平均值"]},{"cell_type":"code","execution_count":298,"metadata":{"collapsed":false,"id":"FE95D42311794F60AE77914F6B08E044","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["10.227982360836924"]},"execution_count":298,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","data.mean().mean()"]},{"cell_type":"markdown","metadata":{"id":"A435AC6481E54B868677E2469A328415","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤9 创建一个名为```loc_stats```的数据框去计算并存储每个location的风速最小值，最大值，平均值和标准差"]},{"cell_type":"code","execution_count":299,"metadata":{"collapsed":false,"id":"21BD2C96315149FBAC150954BFE36D7A","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>min</th>\n","      <th>max</th>\n","      <th>mean</th>\n","      <th>std</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>RPT</th>\n","      <td>0.67</td>\n","      <td>35.80</td>\n","      <td>12.362987</td>\n","      <td>5.618413</td>\n","    </tr>\n","    <tr>\n","      <th>VAL</th>\n","      <td>0.21</td>\n","      <td>33.37</td>\n","      <td>10.644314</td>\n","      <td>5.267356</td>\n","    </tr>\n","    <tr>\n","      <th>ROS</th>\n","      <td>1.50</td>\n","      <td>33.84</td>\n","      <td>11.660526</td>\n","      <td>5.008450</td>\n","    </tr>\n","    <tr>\n","      <th>KIL</th>\n","      <td>0.00</td>\n","      <td>28.46</td>\n","      <td>6.306468</td>\n","      <td>3.605811</td>\n","    </tr>\n","    <tr>\n","      <th>SHA</th>\n","      <td>0.13</td>\n","      <td>37.54</td>\n","      <td>10.455834</td>\n","      <td>4.936125</td>\n","    </tr>\n","    <tr>\n","      <th>BIR</th>\n","      <td>0.00</td>\n","      <td>26.16</td>\n","      <td>7.092254</td>\n","      <td>3.968683</td>\n","    </tr>\n","    <tr>\n","      <th>DUB</th>\n","      <td>0.00</td>\n","      <td>30.37</td>\n","      <td>9.797343</td>\n","      <td>4.977555</td>\n","    </tr>\n","    <tr>\n","      <th>CLA</th>\n","      <td>0.00</td>\n","      <td>31.08</td>\n","      <td>8.495053</td>\n","      <td>4.499449</td>\n","    </tr>\n","    <tr>\n","      <th>MUL</th>\n","      <td>0.00</td>\n","      <td>25.88</td>\n","      <td>8.493590</td>\n","      <td>4.166872</td>\n","    </tr>\n","    <tr>\n","      <th>CLO</th>\n","      <td>0.04</td>\n","      <td>28.21</td>\n","      <td>8.707332</td>\n","      <td>4.503954</td>\n","    </tr>\n","    <tr>\n","      <th>BEL</th>\n","      <td>0.13</td>\n","      <td>42.38</td>\n","      <td>13.121007</td>\n","      <td>5.835037</td>\n","    </tr>\n","    <tr>\n","      <th>MAL</th>\n","      <td>0.67</td>\n","      <td>42.54</td>\n","      <td>15.599079</td>\n","      <td>6.699794</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["      min    max       mean       std\n","RPT  0.67  35.80  12.362987  5.618413\n","VAL  0.21  33.37  10.644314  5.267356\n","ROS  1.50  33.84  11.660526  5.008450\n","KIL  0.00  28.46   6.306468  3.605811\n","SHA  0.13  37.54  10.455834  4.936125\n","BIR  0.00  26.16   7.092254  3.968683\n","DUB  0.00  30.37   9.797343  4.977555\n","CLA  0.00  31.08   8.495053  4.499449\n","MUL  0.00  25.88   8.493590  4.166872\n","CLO  0.04  28.21   8.707332  4.503954\n","BEL  0.13  42.38  13.121007  5.835037\n","MAL  0.67  42.54  15.599079  6.699794"]},"execution_count":299,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","loc_stats = pd.DataFrame()\n","\n","loc_stats['min'] = data.min() # min\n","loc_stats['max'] = data.max() # max \n","loc_stats['mean'] = data.mean() # mean\n","loc_stats['std'] = data.std() # standard deviations\n","\n","loc_stats"]},{"cell_type":"markdown","metadata":{"id":"6E7615F80A374F7283CE6E866797288C","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤10 创建一个名为```day_stats```的数据框去计算并存储所有location的风速最小值，最大值，平均值和标准差"]},{"cell_type":"code","execution_count":300,"metadata":{"collapsed":false,"id":"690306AD53644375857E3FC6E7EA3176","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>min</th>\n","      <th>max</th>\n","      <th>mean</th>\n","      <th>std</th>\n","    </tr>\n","    <tr>\n","      <th>Yr_Mo_Dy</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1961-01-01</th>\n","      <td>9.29</td>\n","      <td>18.50</td>\n","      <td>13.018182</td>\n","      <td>2.808875</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-02</th>\n","      <td>6.50</td>\n","      <td>17.54</td>\n","      <td>11.336364</td>\n","      <td>3.188994</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-03</th>\n","      <td>6.17</td>\n","      <td>18.50</td>\n","      <td>11.641818</td>\n","      <td>3.681912</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-04</th>\n","      <td>1.79</td>\n","      <td>11.75</td>\n","      <td>6.619167</td>\n","      <td>3.198126</td>\n","    </tr>\n","    <tr>\n","      <th>1961-01-05</th>\n","      <td>6.17</td>\n","      <td>13.33</td>\n","      <td>10.630000</td>\n","      <td>2.445356</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["             min    max       mean       std\n","Yr_Mo_Dy                                    \n","1961-01-01  9.29  18.50  13.018182  2.808875\n","1961-01-02  6.50  17.54  11.336364  3.188994\n","1961-01-03  6.17  18.50  11.641818  3.681912\n","1961-01-04  1.79  11.75   6.619167  3.198126\n","1961-01-05  6.17  13.33  10.630000  2.445356"]},"execution_count":300,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","# create the dataframe\n","day_stats = pd.DataFrame()\n","\n","# this time we determine axis equals to one so it gets each row.\n","day_stats['min'] = data.min(axis = 1) # min\n","day_stats['max'] = data.max(axis = 1) # max \n","day_stats['mean'] = data.mean(axis = 1) # mean\n","day_stats['std'] = data.std(axis = 1) # standard deviations\n","\n","day_stats.head()"]},{"cell_type":"markdown","metadata":{"id":"95CFA0ECD5EC4D23A52EA5BC36D02B44","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤11 对于每一个location，计算一月份的平均风速\n","*注意，1961年的1月和1962年的1月应该区别对待*"]},{"cell_type":"code","execution_count":301,"metadata":{"collapsed":false,"id":"77114D8F4CC74EB380372660289C7F9D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["RPT    14.847325\n","VAL    12.914560\n","ROS    13.299624\n","KIL     7.199498\n","SHA    11.667734\n","BIR     8.054839\n","DUB    11.819355\n","CLA     9.512047\n","MUL     9.543208\n","CLO    10.053566\n","BEL    14.550520\n","MAL    18.028763\n","dtype: float64"]},"execution_count":301,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","# creates a new column 'date' and gets the values from the index\n","data['date'] = data.index\n","\n","# creates a column for each value from date\n","data['month'] = data['date'].apply(lambda date: date.month)\n","data['year'] = data['date'].apply(lambda date: date.year)\n","data['day'] = data['date'].apply(lambda date: date.day)\n","\n","# gets all value from the month 1 and assign to janyary_winds\n","january_winds = data.query('month == 1')\n","\n","# gets the mean from january_winds, using .loc to not print the mean of month, year and day\n","january_winds.loc[:,'RPT':\"MAL\"].mean()"]},{"cell_type":"markdown","metadata":{"id":"BFE9BE5CB39B4BFB829D0C6AB74BA1A1","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤12  对于数据记录按照年为频率取样"]},{"cell_type":"code","execution_count":302,"metadata":{"collapsed":false,"id":"FB6B7C0152794B69828EBBB3865F346D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>RPT</th>\n","      <th>VAL</th>\n","      <th>ROS</th>\n","      <th>KIL</th>\n","      <th>SHA</th>\n","      <th>BIR</th>\n","      <th>DUB</th>\n","      <th>CLA</th>\n","      <th>MUL</th>\n","      <th>CLO</th>\n","      <th>BEL</th>\n","      <th>MAL</th>\n","      <th>date</th>\n","      <th>month</th>\n","      <th>year</th>\n","      <th>day</th>\n","    </tr>\n","    <tr>\n","      <th>Yr_Mo_Dy</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1961-01-01</th>\n","      <td>15.04</td>\n","      <td>14.96</td>\n","      <td>13.17</td>\n","      <td>9.29</td>\n","      <td>NaN</td>\n","      <td>9.87</td>\n","      <td>13.67</td>\n","      <td>10.25</td>\n","      <td>10.83</td>\n","      <td>12.58</td>\n","      <td>18.50</td>\n","      <td>15.04</td>\n","      <td>1961-01-01</td>\n","      <td>1</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-01-01</th>\n","      <td>9.29</td>\n","      <td>3.42</td>\n","      <td>11.54</td>\n","      <td>3.50</td>\n","      <td>2.21</td>\n","      <td>1.96</td>\n","      <td>10.41</td>\n","      <td>2.79</td>\n","      <td>3.54</td>\n","      <td>5.17</td>\n","      <td>4.38</td>\n","      <td>7.92</td>\n","      <td>1962-01-01</td>\n","      <td>1</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1963-01-01</th>\n","      <td>15.59</td>\n","      <td>13.62</td>\n","      <td>19.79</td>\n","      <td>8.38</td>\n","      <td>12.25</td>\n","      <td>10.00</td>\n","      <td>23.45</td>\n","      <td>15.71</td>\n","      <td>13.59</td>\n","      <td>14.37</td>\n","      <td>17.58</td>\n","      <td>34.13</td>\n","      <td>1963-01-01</td>\n","      <td>1</td>\n","      <td>1963</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1964-01-01</th>\n","      <td>25.80</td>\n","      <td>22.13</td>\n","      <td>18.21</td>\n","      <td>13.25</td>\n","      <td>21.29</td>\n","      <td>14.79</td>\n","      <td>14.12</td>\n","      <td>19.58</td>\n","      <td>13.25</td>\n","      <td>16.75</td>\n","      <td>28.96</td>\n","      <td>21.00</td>\n","      <td>1964-01-01</td>\n","      <td>1</td>\n","      <td>1964</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1965-01-01</th>\n","      <td>9.54</td>\n","      <td>11.92</td>\n","      <td>9.00</td>\n","      <td>4.38</td>\n","      <td>6.08</td>\n","      <td>5.21</td>\n","      <td>10.25</td>\n","      <td>6.08</td>\n","      <td>5.71</td>\n","      <td>8.63</td>\n","      <td>12.04</td>\n","      <td>17.41</td>\n","      <td>1965-01-01</td>\n","      <td>1</td>\n","      <td>1965</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1966-01-01</th>\n","      <td>22.04</td>\n","      <td>21.50</td>\n","      <td>17.08</td>\n","      <td>12.75</td>\n","      <td>22.17</td>\n","      <td>15.59</td>\n","      <td>21.79</td>\n","      <td>18.12</td>\n","      <td>16.66</td>\n","      <td>17.83</td>\n","      <td>28.33</td>\n","      <td>23.79</td>\n","      <td>1966-01-01</td>\n","      <td>1</td>\n","      <td>1966</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1967-01-01</th>\n","      <td>6.46</td>\n","      <td>4.46</td>\n","      <td>6.50</td>\n","      <td>3.21</td>\n","      <td>6.67</td>\n","      <td>3.79</td>\n","      <td>11.38</td>\n","      <td>3.83</td>\n","      <td>7.71</td>\n","      <td>9.08</td>\n","      <td>10.67</td>\n","      <td>20.91</td>\n","      <td>1967-01-01</td>\n","      <td>1</td>\n","      <td>1967</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1968-01-01</th>\n","      <td>30.04</td>\n","      <td>17.88</td>\n","      <td>16.25</td>\n","      <td>16.25</td>\n","      <td>21.79</td>\n","      <td>12.54</td>\n","      <td>18.16</td>\n","      <td>16.62</td>\n","      <td>18.75</td>\n","      <td>17.62</td>\n","      <td>22.25</td>\n","      <td>27.29</td>\n","      <td>1968-01-01</td>\n","      <td>1</td>\n","      <td>1968</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1969-01-01</th>\n","      <td>6.13</td>\n","      <td>1.63</td>\n","      <td>5.41</td>\n","      <td>1.08</td>\n","      <td>2.54</td>\n","      <td>1.00</td>\n","      <td>8.50</td>\n","      <td>2.42</td>\n","      <td>4.58</td>\n","      <td>6.34</td>\n","      <td>9.17</td>\n","      <td>16.71</td>\n","      <td>1969-01-01</td>\n","      <td>1</td>\n","      <td>1969</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1970-01-01</th>\n","      <td>9.59</td>\n","      <td>2.96</td>\n","      <td>11.79</td>\n","      <td>3.42</td>\n","      <td>6.13</td>\n","      <td>4.08</td>\n","      <td>9.00</td>\n","      <td>4.46</td>\n","      <td>7.29</td>\n","      <td>3.50</td>\n","      <td>7.33</td>\n","      <td>13.00</td>\n","      <td>1970-01-01</td>\n","      <td>1</td>\n","      <td>1970</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1971-01-01</th>\n","      <td>3.71</td>\n","      <td>0.79</td>\n","      <td>4.71</td>\n","      <td>0.17</td>\n","      <td>1.42</td>\n","      <td>1.04</td>\n","      <td>4.63</td>\n","      <td>0.75</td>\n","      <td>1.54</td>\n","      <td>1.08</td>\n","      <td>4.21</td>\n","      <td>9.54</td>\n","      <td>1971-01-01</td>\n","      <td>1</td>\n","      <td>1971</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1972-01-01</th>\n","      <td>9.29</td>\n","      <td>3.63</td>\n","      <td>14.54</td>\n","      <td>4.25</td>\n","      <td>6.75</td>\n","      <td>4.42</td>\n","      <td>13.00</td>\n","      <td>5.33</td>\n","      <td>10.04</td>\n","      <td>8.54</td>\n","      <td>8.71</td>\n","      <td>19.17</td>\n","      <td>1972-01-01</td>\n","      <td>1</td>\n","      <td>1972</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1973-01-01</th>\n","      <td>16.50</td>\n","      <td>15.92</td>\n","      <td>14.62</td>\n","      <td>7.41</td>\n","      <td>8.29</td>\n","      <td>11.21</td>\n","      <td>13.54</td>\n","      <td>7.79</td>\n","      <td>10.46</td>\n","      <td>10.79</td>\n","      <td>13.37</td>\n","      <td>9.71</td>\n","      <td>1973-01-01</td>\n","      <td>1</td>\n","      <td>1973</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1974-01-01</th>\n","      <td>23.21</td>\n","      <td>16.54</td>\n","      <td>16.08</td>\n","      <td>9.75</td>\n","      <td>15.83</td>\n","      <td>11.46</td>\n","      <td>9.54</td>\n","      <td>13.54</td>\n","      <td>13.83</td>\n","      <td>16.66</td>\n","      <td>17.21</td>\n","      <td>25.29</td>\n","      <td>1974-01-01</td>\n","      <td>1</td>\n","      <td>1974</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1975-01-01</th>\n","      <td>14.04</td>\n","      <td>13.54</td>\n","      <td>11.29</td>\n","      <td>5.46</td>\n","      <td>12.58</td>\n","      <td>5.58</td>\n","      <td>8.12</td>\n","      <td>8.96</td>\n","      <td>9.29</td>\n","      <td>5.17</td>\n","      <td>7.71</td>\n","      <td>11.63</td>\n","      <td>1975-01-01</td>\n","      <td>1</td>\n","      <td>1975</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1976-01-01</th>\n","      <td>18.34</td>\n","      <td>17.67</td>\n","      <td>14.83</td>\n","      <td>8.00</td>\n","      <td>16.62</td>\n","      <td>10.13</td>\n","      <td>13.17</td>\n","      <td>9.04</td>\n","      <td>13.13</td>\n","      <td>5.75</td>\n","      <td>11.38</td>\n","      <td>14.96</td>\n","      <td>1976-01-01</td>\n","      <td>1</td>\n","      <td>1976</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-01-01</th>\n","      <td>20.04</td>\n","      <td>11.92</td>\n","      <td>20.25</td>\n","      <td>9.13</td>\n","      <td>9.29</td>\n","      <td>8.04</td>\n","      <td>10.75</td>\n","      <td>5.88</td>\n","      <td>9.00</td>\n","      <td>9.00</td>\n","      <td>14.88</td>\n","      <td>25.70</td>\n","      <td>1977-01-01</td>\n","      <td>1</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-01-01</th>\n","      <td>8.33</td>\n","      <td>7.12</td>\n","      <td>7.71</td>\n","      <td>3.54</td>\n","      <td>8.50</td>\n","      <td>7.50</td>\n","      <td>14.71</td>\n","      <td>10.00</td>\n","      <td>11.83</td>\n","      <td>10.00</td>\n","      <td>15.09</td>\n","      <td>20.46</td>\n","      <td>1978-01-01</td>\n","      <td>1</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["              RPT    VAL    ROS    KIL    SHA    BIR    DUB    CLA    MUL  \\\n","Yr_Mo_Dy                                                                    \n","1961-01-01  15.04  14.96  13.17   9.29    NaN   9.87  13.67  10.25  10.83   \n","1962-01-01   9.29   3.42  11.54   3.50   2.21   1.96  10.41   2.79   3.54   \n","1963-01-01  15.59  13.62  19.79   8.38  12.25  10.00  23.45  15.71  13.59   \n","1964-01-01  25.80  22.13  18.21  13.25  21.29  14.79  14.12  19.58  13.25   \n","1965-01-01   9.54  11.92   9.00   4.38   6.08   5.21  10.25   6.08   5.71   \n","1966-01-01  22.04  21.50  17.08  12.75  22.17  15.59  21.79  18.12  16.66   \n","1967-01-01   6.46   4.46   6.50   3.21   6.67   3.79  11.38   3.83   7.71   \n","1968-01-01  30.04  17.88  16.25  16.25  21.79  12.54  18.16  16.62  18.75   \n","1969-01-01   6.13   1.63   5.41   1.08   2.54   1.00   8.50   2.42   4.58   \n","1970-01-01   9.59   2.96  11.79   3.42   6.13   4.08   9.00   4.46   7.29   \n","1971-01-01   3.71   0.79   4.71   0.17   1.42   1.04   4.63   0.75   1.54   \n","1972-01-01   9.29   3.63  14.54   4.25   6.75   4.42  13.00   5.33  10.04   \n","1973-01-01  16.50  15.92  14.62   7.41   8.29  11.21  13.54   7.79  10.46   \n","1974-01-01  23.21  16.54  16.08   9.75  15.83  11.46   9.54  13.54  13.83   \n","1975-01-01  14.04  13.54  11.29   5.46  12.58   5.58   8.12   8.96   9.29   \n","1976-01-01  18.34  17.67  14.83   8.00  16.62  10.13  13.17   9.04  13.13   \n","1977-01-01  20.04  11.92  20.25   9.13   9.29   8.04  10.75   5.88   9.00   \n","1978-01-01   8.33   7.12   7.71   3.54   8.50   7.50  14.71  10.00  11.83   \n","\n","              CLO    BEL    MAL       date  month  year  day  \n","Yr_Mo_Dy                                                      \n","1961-01-01  12.58  18.50  15.04 1961-01-01      1  1961    1  \n","1962-01-01   5.17   4.38   7.92 1962-01-01      1  1962    1  \n","1963-01-01  14.37  17.58  34.13 1963-01-01      1  1963    1  \n","1964-01-01  16.75  28.96  21.00 1964-01-01      1  1964    1  \n","1965-01-01   8.63  12.04  17.41 1965-01-01      1  1965    1  \n","1966-01-01  17.83  28.33  23.79 1966-01-01      1  1966    1  \n","1967-01-01   9.08  10.67  20.91 1967-01-01      1  1967    1  \n","1968-01-01  17.62  22.25  27.29 1968-01-01      1  1968    1  \n","1969-01-01   6.34   9.17  16.71 1969-01-01      1  1969    1  \n","1970-01-01   3.50   7.33  13.00 1970-01-01      1  1970    1  \n","1971-01-01   1.08   4.21   9.54 1971-01-01      1  1971    1  \n","1972-01-01   8.54   8.71  19.17 1972-01-01      1  1972    1  \n","1973-01-01  10.79  13.37   9.71 1973-01-01      1  1973    1  \n","1974-01-01  16.66  17.21  25.29 1974-01-01      1  1974    1  \n","1975-01-01   5.17   7.71  11.63 1975-01-01      1  1975    1  \n","1976-01-01   5.75  11.38  14.96 1976-01-01      1  1976    1  \n","1977-01-01   9.00  14.88  25.70 1977-01-01      1  1977    1  \n","1978-01-01  10.00  15.09  20.46 1978-01-01      1  1978    1  "]},"execution_count":302,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","data.query('month == 1 and day == 1')"]},{"cell_type":"markdown","metadata":{"id":"F042E1F29B824B248BF72E18BC1124FD","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤13 对于数据记录按照月为频率取样"]},{"cell_type":"code","execution_count":303,"metadata":{"collapsed":false,"id":"CB8005ECB2BF46F8A7956F659B8D1339","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>RPT</th>\n","      <th>VAL</th>\n","      <th>ROS</th>\n","      <th>KIL</th>\n","      <th>SHA</th>\n","      <th>BIR</th>\n","      <th>DUB</th>\n","      <th>CLA</th>\n","      <th>MUL</th>\n","      <th>CLO</th>\n","      <th>BEL</th>\n","      <th>MAL</th>\n","      <th>date</th>\n","      <th>month</th>\n","      <th>year</th>\n","      <th>day</th>\n","    </tr>\n","    <tr>\n","      <th>Yr_Mo_Dy</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1961-01-01</th>\n","      <td>15.04</td>\n","      <td>14.96</td>\n","      <td>13.17</td>\n","      <td>9.29</td>\n","      <td>NaN</td>\n","      <td>9.87</td>\n","      <td>13.67</td>\n","      <td>10.25</td>\n","      <td>10.83</td>\n","      <td>12.58</td>\n","      <td>18.50</td>\n","      <td>15.04</td>\n","      <td>1961-01-01</td>\n","      <td>1</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-02-01</th>\n","      <td>14.25</td>\n","      <td>15.12</td>\n","      <td>9.04</td>\n","      <td>5.88</td>\n","      <td>12.08</td>\n","      <td>7.17</td>\n","      <td>10.17</td>\n","      <td>3.63</td>\n","      <td>6.50</td>\n","      <td>5.50</td>\n","      <td>9.17</td>\n","      <td>8.00</td>\n","      <td>1961-02-01</td>\n","      <td>2</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-03-01</th>\n","      <td>12.67</td>\n","      <td>13.13</td>\n","      <td>11.79</td>\n","      <td>6.42</td>\n","      <td>9.79</td>\n","      <td>8.54</td>\n","      <td>10.25</td>\n","      <td>13.29</td>\n","      <td>NaN</td>\n","      <td>12.21</td>\n","      <td>20.62</td>\n","      <td>NaN</td>\n","      <td>1961-03-01</td>\n","      <td>3</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-04-01</th>\n","      <td>8.38</td>\n","      <td>6.34</td>\n","      <td>8.33</td>\n","      <td>6.75</td>\n","      <td>9.33</td>\n","      <td>9.54</td>\n","      <td>11.67</td>\n","      <td>8.21</td>\n","      <td>11.21</td>\n","      <td>6.46</td>\n","      <td>11.96</td>\n","      <td>7.17</td>\n","      <td>1961-04-01</td>\n","      <td>4</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-05-01</th>\n","      <td>15.87</td>\n","      <td>13.88</td>\n","      <td>15.37</td>\n","      <td>9.79</td>\n","      <td>13.46</td>\n","      <td>10.17</td>\n","      <td>9.96</td>\n","      <td>14.04</td>\n","      <td>9.75</td>\n","      <td>9.92</td>\n","      <td>18.63</td>\n","      <td>11.12</td>\n","      <td>1961-05-01</td>\n","      <td>5</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-06-01</th>\n","      <td>15.92</td>\n","      <td>9.59</td>\n","      <td>12.04</td>\n","      <td>8.79</td>\n","      <td>11.54</td>\n","      <td>6.04</td>\n","      <td>9.75</td>\n","      <td>8.29</td>\n","      <td>9.33</td>\n","      <td>10.34</td>\n","      <td>10.67</td>\n","      <td>12.12</td>\n","      <td>1961-06-01</td>\n","      <td>6</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-07-01</th>\n","      <td>7.21</td>\n","      <td>6.83</td>\n","      <td>7.71</td>\n","      <td>4.42</td>\n","      <td>8.46</td>\n","      <td>4.79</td>\n","      <td>6.71</td>\n","      <td>6.00</td>\n","      <td>5.79</td>\n","      <td>7.96</td>\n","      <td>6.96</td>\n","      <td>8.71</td>\n","      <td>1961-07-01</td>\n","      <td>7</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-08-01</th>\n","      <td>9.59</td>\n","      <td>5.09</td>\n","      <td>5.54</td>\n","      <td>4.63</td>\n","      <td>8.29</td>\n","      <td>5.25</td>\n","      <td>4.21</td>\n","      <td>5.25</td>\n","      <td>5.37</td>\n","      <td>5.41</td>\n","      <td>8.38</td>\n","      <td>9.08</td>\n","      <td>1961-08-01</td>\n","      <td>8</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-09-01</th>\n","      <td>5.58</td>\n","      <td>1.13</td>\n","      <td>4.96</td>\n","      <td>3.04</td>\n","      <td>4.25</td>\n","      <td>2.25</td>\n","      <td>4.63</td>\n","      <td>2.71</td>\n","      <td>3.67</td>\n","      <td>6.00</td>\n","      <td>4.79</td>\n","      <td>5.41</td>\n","      <td>1961-09-01</td>\n","      <td>9</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-10-01</th>\n","      <td>14.25</td>\n","      <td>12.87</td>\n","      <td>7.87</td>\n","      <td>8.00</td>\n","      <td>13.00</td>\n","      <td>7.75</td>\n","      <td>5.83</td>\n","      <td>9.00</td>\n","      <td>7.08</td>\n","      <td>5.29</td>\n","      <td>11.79</td>\n","      <td>4.04</td>\n","      <td>1961-10-01</td>\n","      <td>10</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-11-01</th>\n","      <td>13.21</td>\n","      <td>13.13</td>\n","      <td>14.33</td>\n","      <td>8.54</td>\n","      <td>12.17</td>\n","      <td>10.21</td>\n","      <td>13.08</td>\n","      <td>12.17</td>\n","      <td>10.92</td>\n","      <td>13.54</td>\n","      <td>20.17</td>\n","      <td>20.04</td>\n","      <td>1961-11-01</td>\n","      <td>11</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1961-12-01</th>\n","      <td>9.67</td>\n","      <td>7.75</td>\n","      <td>8.00</td>\n","      <td>3.96</td>\n","      <td>6.00</td>\n","      <td>2.75</td>\n","      <td>7.25</td>\n","      <td>2.50</td>\n","      <td>5.58</td>\n","      <td>5.58</td>\n","      <td>7.79</td>\n","      <td>11.17</td>\n","      <td>1961-12-01</td>\n","      <td>12</td>\n","      <td>1961</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-01-01</th>\n","      <td>9.29</td>\n","      <td>3.42</td>\n","      <td>11.54</td>\n","      <td>3.50</td>\n","      <td>2.21</td>\n","      <td>1.96</td>\n","      <td>10.41</td>\n","      <td>2.79</td>\n","      <td>3.54</td>\n","      <td>5.17</td>\n","      <td>4.38</td>\n","      <td>7.92</td>\n","      <td>1962-01-01</td>\n","      <td>1</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-02-01</th>\n","      <td>19.12</td>\n","      <td>13.96</td>\n","      <td>12.21</td>\n","      <td>10.58</td>\n","      <td>15.71</td>\n","      <td>10.63</td>\n","      <td>15.71</td>\n","      <td>11.08</td>\n","      <td>13.17</td>\n","      <td>12.62</td>\n","      <td>17.67</td>\n","      <td>22.71</td>\n","      <td>1962-02-01</td>\n","      <td>2</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-03-01</th>\n","      <td>8.21</td>\n","      <td>4.83</td>\n","      <td>9.00</td>\n","      <td>4.83</td>\n","      <td>6.00</td>\n","      <td>2.21</td>\n","      <td>7.96</td>\n","      <td>1.87</td>\n","      <td>4.08</td>\n","      <td>3.92</td>\n","      <td>4.08</td>\n","      <td>5.41</td>\n","      <td>1962-03-01</td>\n","      <td>3</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-04-01</th>\n","      <td>14.33</td>\n","      <td>12.25</td>\n","      <td>11.87</td>\n","      <td>10.37</td>\n","      <td>14.92</td>\n","      <td>11.00</td>\n","      <td>19.79</td>\n","      <td>11.67</td>\n","      <td>14.09</td>\n","      <td>15.46</td>\n","      <td>16.62</td>\n","      <td>23.58</td>\n","      <td>1962-04-01</td>\n","      <td>4</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-05-01</th>\n","      <td>9.62</td>\n","      <td>9.54</td>\n","      <td>3.58</td>\n","      <td>3.33</td>\n","      <td>8.75</td>\n","      <td>3.75</td>\n","      <td>2.25</td>\n","      <td>2.58</td>\n","      <td>1.67</td>\n","      <td>2.37</td>\n","      <td>7.29</td>\n","      <td>3.25</td>\n","      <td>1962-05-01</td>\n","      <td>5</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-06-01</th>\n","      <td>5.88</td>\n","      <td>6.29</td>\n","      <td>8.67</td>\n","      <td>5.21</td>\n","      <td>5.00</td>\n","      <td>4.25</td>\n","      <td>5.91</td>\n","      <td>5.41</td>\n","      <td>4.79</td>\n","      <td>9.25</td>\n","      <td>5.25</td>\n","      <td>10.71</td>\n","      <td>1962-06-01</td>\n","      <td>6</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-07-01</th>\n","      <td>8.67</td>\n","      <td>4.17</td>\n","      <td>6.92</td>\n","      <td>6.71</td>\n","      <td>8.17</td>\n","      <td>5.66</td>\n","      <td>11.17</td>\n","      <td>9.38</td>\n","      <td>8.75</td>\n","      <td>11.12</td>\n","      <td>10.25</td>\n","      <td>17.08</td>\n","      <td>1962-07-01</td>\n","      <td>7</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-08-01</th>\n","      <td>4.58</td>\n","      <td>5.37</td>\n","      <td>6.04</td>\n","      <td>2.29</td>\n","      <td>7.87</td>\n","      <td>3.71</td>\n","      <td>4.46</td>\n","      <td>2.58</td>\n","      <td>4.00</td>\n","      <td>4.79</td>\n","      <td>7.21</td>\n","      <td>7.46</td>\n","      <td>1962-08-01</td>\n","      <td>8</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-09-01</th>\n","      <td>10.00</td>\n","      <td>12.08</td>\n","      <td>10.96</td>\n","      <td>9.25</td>\n","      <td>9.29</td>\n","      <td>7.62</td>\n","      <td>7.41</td>\n","      <td>8.75</td>\n","      <td>7.67</td>\n","      <td>9.62</td>\n","      <td>14.58</td>\n","      <td>11.92</td>\n","      <td>1962-09-01</td>\n","      <td>9</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-10-01</th>\n","      <td>14.58</td>\n","      <td>7.83</td>\n","      <td>19.21</td>\n","      <td>10.08</td>\n","      <td>11.54</td>\n","      <td>8.38</td>\n","      <td>13.29</td>\n","      <td>10.63</td>\n","      <td>8.21</td>\n","      <td>12.92</td>\n","      <td>18.05</td>\n","      <td>18.12</td>\n","      <td>1962-10-01</td>\n","      <td>10</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-11-01</th>\n","      <td>16.88</td>\n","      <td>13.25</td>\n","      <td>16.00</td>\n","      <td>8.96</td>\n","      <td>13.46</td>\n","      <td>11.46</td>\n","      <td>10.46</td>\n","      <td>10.17</td>\n","      <td>10.37</td>\n","      <td>13.21</td>\n","      <td>14.83</td>\n","      <td>15.16</td>\n","      <td>1962-11-01</td>\n","      <td>11</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1962-12-01</th>\n","      <td>18.38</td>\n","      <td>15.41</td>\n","      <td>11.75</td>\n","      <td>6.79</td>\n","      <td>12.21</td>\n","      <td>8.04</td>\n","      <td>8.42</td>\n","      <td>10.83</td>\n","      <td>5.66</td>\n","      <td>9.08</td>\n","      <td>11.50</td>\n","      <td>11.50</td>\n","      <td>1962-12-01</td>\n","      <td>12</td>\n","      <td>1962</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1963-01-01</th>\n","      <td>15.59</td>\n","      <td>13.62</td>\n","      <td>19.79</td>\n","      <td>8.38</td>\n","      <td>12.25</td>\n","      <td>10.00</td>\n","      <td>23.45</td>\n","      <td>15.71</td>\n","      <td>13.59</td>\n","      <td>14.37</td>\n","      <td>17.58</td>\n","      <td>34.13</td>\n","      <td>1963-01-01</td>\n","      <td>1</td>\n","      <td>1963</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1963-02-01</th>\n","      <td>15.41</td>\n","      <td>7.62</td>\n","      <td>24.67</td>\n","      <td>11.42</td>\n","      <td>9.21</td>\n","      <td>8.17</td>\n","      <td>14.04</td>\n","      <td>7.54</td>\n","      <td>7.54</td>\n","      <td>10.08</td>\n","      <td>10.17</td>\n","      <td>17.67</td>\n","      <td>1963-02-01</td>\n","      <td>2</td>\n","      <td>1963</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1963-03-01</th>\n","      <td>16.75</td>\n","      <td>19.67</td>\n","      <td>17.67</td>\n","      <td>8.87</td>\n","      <td>19.08</td>\n","      <td>15.37</td>\n","      <td>16.21</td>\n","      <td>14.29</td>\n","      <td>11.29</td>\n","      <td>9.21</td>\n","      <td>19.92</td>\n","      <td>19.79</td>\n","      <td>1963-03-01</td>\n","      <td>3</td>\n","      <td>1963</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1963-04-01</th>\n","      <td>10.54</td>\n","      <td>9.59</td>\n","      <td>12.46</td>\n","      <td>7.33</td>\n","      <td>9.46</td>\n","      <td>9.59</td>\n","      <td>11.79</td>\n","      <td>11.87</td>\n","      <td>9.79</td>\n","      <td>10.71</td>\n","      <td>13.37</td>\n","      <td>18.21</td>\n","      <td>1963-04-01</td>\n","      <td>4</td>\n","      <td>1963</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1963-05-01</th>\n","      <td>18.79</td>\n","      <td>14.17</td>\n","      <td>13.59</td>\n","      <td>11.63</td>\n","      <td>14.17</td>\n","      <td>11.96</td>\n","      <td>14.46</td>\n","      <td>12.46</td>\n","      <td>12.87</td>\n","      <td>13.96</td>\n","      <td>15.29</td>\n","      <td>21.62</td>\n","      <td>1963-05-01</td>\n","      <td>5</td>\n","      <td>1963</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1963-06-01</th>\n","      <td>13.37</td>\n","      <td>6.87</td>\n","      <td>12.00</td>\n","      <td>8.50</td>\n","      <td>10.04</td>\n","      <td>9.42</td>\n","      <td>10.92</td>\n","      <td>12.96</td>\n","      <td>11.79</td>\n","      <td>11.04</td>\n","      <td>10.92</td>\n","      <td>13.67</td>\n","      <td>1963-06-01</td>\n","      <td>6</td>\n","      <td>1963</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>...</th>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","    </tr>\n","    <tr>\n","      <th>1976-07-01</th>\n","      <td>8.50</td>\n","      <td>1.75</td>\n","      <td>6.58</td>\n","      <td>2.13</td>\n","      <td>2.75</td>\n","      <td>2.21</td>\n","      <td>5.37</td>\n","      <td>2.04</td>\n","      <td>5.88</td>\n","      <td>4.50</td>\n","      <td>4.96</td>\n","      <td>10.63</td>\n","      <td>1976-07-01</td>\n","      <td>7</td>\n","      <td>1976</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1976-08-01</th>\n","      <td>13.00</td>\n","      <td>8.38</td>\n","      <td>8.63</td>\n","      <td>5.83</td>\n","      <td>12.92</td>\n","      <td>8.25</td>\n","      <td>13.00</td>\n","      <td>9.42</td>\n","      <td>10.58</td>\n","      <td>11.34</td>\n","      <td>14.21</td>\n","      <td>20.25</td>\n","      <td>1976-08-01</td>\n","      <td>8</td>\n","      <td>1976</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1976-09-01</th>\n","      <td>11.87</td>\n","      <td>11.00</td>\n","      <td>7.38</td>\n","      <td>6.87</td>\n","      <td>7.75</td>\n","      <td>8.33</td>\n","      <td>10.34</td>\n","      <td>6.46</td>\n","      <td>10.17</td>\n","      <td>9.29</td>\n","      <td>12.75</td>\n","      <td>19.55</td>\n","      <td>1976-09-01</td>\n","      <td>9</td>\n","      <td>1976</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1976-10-01</th>\n","      <td>10.96</td>\n","      <td>6.71</td>\n","      <td>10.41</td>\n","      <td>4.63</td>\n","      <td>7.58</td>\n","      <td>5.04</td>\n","      <td>5.04</td>\n","      <td>5.54</td>\n","      <td>6.50</td>\n","      <td>3.92</td>\n","      <td>6.79</td>\n","      <td>5.00</td>\n","      <td>1976-10-01</td>\n","      <td>10</td>\n","      <td>1976</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1976-11-01</th>\n","      <td>13.96</td>\n","      <td>15.67</td>\n","      <td>10.29</td>\n","      <td>6.46</td>\n","      <td>12.79</td>\n","      <td>9.08</td>\n","      <td>10.00</td>\n","      <td>9.67</td>\n","      <td>10.21</td>\n","      <td>11.63</td>\n","      <td>23.09</td>\n","      <td>21.96</td>\n","      <td>1976-11-01</td>\n","      <td>11</td>\n","      <td>1976</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1976-12-01</th>\n","      <td>13.46</td>\n","      <td>16.42</td>\n","      <td>9.21</td>\n","      <td>4.54</td>\n","      <td>10.75</td>\n","      <td>8.67</td>\n","      <td>10.88</td>\n","      <td>4.83</td>\n","      <td>8.79</td>\n","      <td>5.91</td>\n","      <td>8.83</td>\n","      <td>13.67</td>\n","      <td>1976-12-01</td>\n","      <td>12</td>\n","      <td>1976</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-01-01</th>\n","      <td>20.04</td>\n","      <td>11.92</td>\n","      <td>20.25</td>\n","      <td>9.13</td>\n","      <td>9.29</td>\n","      <td>8.04</td>\n","      <td>10.75</td>\n","      <td>5.88</td>\n","      <td>9.00</td>\n","      <td>9.00</td>\n","      <td>14.88</td>\n","      <td>25.70</td>\n","      <td>1977-01-01</td>\n","      <td>1</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-02-01</th>\n","      <td>11.83</td>\n","      <td>9.71</td>\n","      <td>11.00</td>\n","      <td>4.25</td>\n","      <td>8.58</td>\n","      <td>8.71</td>\n","      <td>6.17</td>\n","      <td>5.66</td>\n","      <td>8.29</td>\n","      <td>7.58</td>\n","      <td>11.71</td>\n","      <td>16.50</td>\n","      <td>1977-02-01</td>\n","      <td>2</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-03-01</th>\n","      <td>8.63</td>\n","      <td>14.83</td>\n","      <td>10.29</td>\n","      <td>3.75</td>\n","      <td>6.63</td>\n","      <td>8.79</td>\n","      <td>5.00</td>\n","      <td>8.12</td>\n","      <td>7.87</td>\n","      <td>6.42</td>\n","      <td>13.54</td>\n","      <td>13.67</td>\n","      <td>1977-03-01</td>\n","      <td>3</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-04-01</th>\n","      <td>21.67</td>\n","      <td>16.00</td>\n","      <td>17.33</td>\n","      <td>13.59</td>\n","      <td>20.83</td>\n","      <td>15.96</td>\n","      <td>25.62</td>\n","      <td>17.62</td>\n","      <td>19.41</td>\n","      <td>20.67</td>\n","      <td>24.37</td>\n","      <td>30.09</td>\n","      <td>1977-04-01</td>\n","      <td>4</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-05-01</th>\n","      <td>6.42</td>\n","      <td>7.12</td>\n","      <td>8.67</td>\n","      <td>3.58</td>\n","      <td>4.58</td>\n","      <td>4.00</td>\n","      <td>6.75</td>\n","      <td>6.13</td>\n","      <td>3.33</td>\n","      <td>4.50</td>\n","      <td>19.21</td>\n","      <td>12.38</td>\n","      <td>1977-05-01</td>\n","      <td>5</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-06-01</th>\n","      <td>7.08</td>\n","      <td>5.25</td>\n","      <td>9.71</td>\n","      <td>2.83</td>\n","      <td>2.21</td>\n","      <td>3.50</td>\n","      <td>5.29</td>\n","      <td>1.42</td>\n","      <td>2.00</td>\n","      <td>0.92</td>\n","      <td>5.21</td>\n","      <td>5.63</td>\n","      <td>1977-06-01</td>\n","      <td>6</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-07-01</th>\n","      <td>15.41</td>\n","      <td>16.29</td>\n","      <td>17.08</td>\n","      <td>6.25</td>\n","      <td>11.83</td>\n","      <td>11.83</td>\n","      <td>12.29</td>\n","      <td>10.58</td>\n","      <td>10.41</td>\n","      <td>7.21</td>\n","      <td>17.37</td>\n","      <td>7.83</td>\n","      <td>1977-07-01</td>\n","      <td>7</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-08-01</th>\n","      <td>4.33</td>\n","      <td>2.96</td>\n","      <td>4.42</td>\n","      <td>2.33</td>\n","      <td>0.96</td>\n","      <td>1.08</td>\n","      <td>4.96</td>\n","      <td>1.87</td>\n","      <td>2.33</td>\n","      <td>2.04</td>\n","      <td>10.50</td>\n","      <td>9.83</td>\n","      <td>1977-08-01</td>\n","      <td>8</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-09-01</th>\n","      <td>17.37</td>\n","      <td>16.33</td>\n","      <td>16.83</td>\n","      <td>8.58</td>\n","      <td>14.46</td>\n","      <td>11.83</td>\n","      <td>15.09</td>\n","      <td>13.92</td>\n","      <td>13.29</td>\n","      <td>13.88</td>\n","      <td>23.29</td>\n","      <td>25.17</td>\n","      <td>1977-09-01</td>\n","      <td>9</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-10-01</th>\n","      <td>16.75</td>\n","      <td>15.34</td>\n","      <td>12.25</td>\n","      <td>9.42</td>\n","      <td>16.38</td>\n","      <td>11.38</td>\n","      <td>18.50</td>\n","      <td>13.92</td>\n","      <td>14.09</td>\n","      <td>14.46</td>\n","      <td>22.34</td>\n","      <td>29.67</td>\n","      <td>1977-10-01</td>\n","      <td>10</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-11-01</th>\n","      <td>16.71</td>\n","      <td>11.54</td>\n","      <td>12.17</td>\n","      <td>4.17</td>\n","      <td>8.54</td>\n","      <td>7.17</td>\n","      <td>11.12</td>\n","      <td>6.46</td>\n","      <td>8.25</td>\n","      <td>6.21</td>\n","      <td>11.04</td>\n","      <td>15.63</td>\n","      <td>1977-11-01</td>\n","      <td>11</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1977-12-01</th>\n","      <td>13.37</td>\n","      <td>10.92</td>\n","      <td>12.42</td>\n","      <td>2.37</td>\n","      <td>5.79</td>\n","      <td>6.13</td>\n","      <td>8.96</td>\n","      <td>7.38</td>\n","      <td>6.29</td>\n","      <td>5.71</td>\n","      <td>8.54</td>\n","      <td>12.42</td>\n","      <td>1977-12-01</td>\n","      <td>12</td>\n","      <td>1977</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-01-01</th>\n","      <td>8.33</td>\n","      <td>7.12</td>\n","      <td>7.71</td>\n","      <td>3.54</td>\n","      <td>8.50</td>\n","      <td>7.50</td>\n","      <td>14.71</td>\n","      <td>10.00</td>\n","      <td>11.83</td>\n","      <td>10.00</td>\n","      <td>15.09</td>\n","      <td>20.46</td>\n","      <td>1978-01-01</td>\n","      <td>1</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-02-01</th>\n","      <td>27.25</td>\n","      <td>24.21</td>\n","      <td>18.16</td>\n","      <td>17.46</td>\n","      <td>27.54</td>\n","      <td>18.05</td>\n","      <td>20.96</td>\n","      <td>25.04</td>\n","      <td>20.04</td>\n","      <td>17.50</td>\n","      <td>27.71</td>\n","      <td>21.12</td>\n","      <td>1978-02-01</td>\n","      <td>2</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-03-01</th>\n","      <td>15.04</td>\n","      <td>6.21</td>\n","      <td>16.04</td>\n","      <td>7.87</td>\n","      <td>6.42</td>\n","      <td>6.67</td>\n","      <td>12.29</td>\n","      <td>8.00</td>\n","      <td>10.58</td>\n","      <td>9.33</td>\n","      <td>5.41</td>\n","      <td>17.00</td>\n","      <td>1978-03-01</td>\n","      <td>3</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-04-01</th>\n","      <td>3.42</td>\n","      <td>7.58</td>\n","      <td>2.71</td>\n","      <td>1.38</td>\n","      <td>3.46</td>\n","      <td>2.08</td>\n","      <td>2.67</td>\n","      <td>4.75</td>\n","      <td>4.83</td>\n","      <td>1.67</td>\n","      <td>7.33</td>\n","      <td>13.67</td>\n","      <td>1978-04-01</td>\n","      <td>4</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-05-01</th>\n","      <td>10.54</td>\n","      <td>12.21</td>\n","      <td>9.08</td>\n","      <td>5.29</td>\n","      <td>11.00</td>\n","      <td>10.08</td>\n","      <td>11.17</td>\n","      <td>13.75</td>\n","      <td>11.87</td>\n","      <td>11.79</td>\n","      <td>12.87</td>\n","      <td>27.16</td>\n","      <td>1978-05-01</td>\n","      <td>5</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-06-01</th>\n","      <td>10.37</td>\n","      <td>11.42</td>\n","      <td>6.46</td>\n","      <td>6.04</td>\n","      <td>11.25</td>\n","      <td>7.50</td>\n","      <td>6.46</td>\n","      <td>5.96</td>\n","      <td>7.79</td>\n","      <td>5.46</td>\n","      <td>5.50</td>\n","      <td>10.41</td>\n","      <td>1978-06-01</td>\n","      <td>6</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-07-01</th>\n","      <td>12.46</td>\n","      <td>10.63</td>\n","      <td>11.17</td>\n","      <td>6.75</td>\n","      <td>12.92</td>\n","      <td>9.04</td>\n","      <td>12.42</td>\n","      <td>9.62</td>\n","      <td>12.08</td>\n","      <td>8.04</td>\n","      <td>14.04</td>\n","      <td>16.17</td>\n","      <td>1978-07-01</td>\n","      <td>7</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-08-01</th>\n","      <td>19.33</td>\n","      <td>15.09</td>\n","      <td>20.17</td>\n","      <td>8.83</td>\n","      <td>12.62</td>\n","      <td>10.41</td>\n","      <td>9.33</td>\n","      <td>12.33</td>\n","      <td>9.50</td>\n","      <td>9.92</td>\n","      <td>15.75</td>\n","      <td>18.00</td>\n","      <td>1978-08-01</td>\n","      <td>8</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-09-01</th>\n","      <td>8.42</td>\n","      <td>6.13</td>\n","      <td>9.87</td>\n","      <td>5.25</td>\n","      <td>3.21</td>\n","      <td>5.71</td>\n","      <td>7.25</td>\n","      <td>3.50</td>\n","      <td>7.33</td>\n","      <td>6.50</td>\n","      <td>7.62</td>\n","      <td>15.96</td>\n","      <td>1978-09-01</td>\n","      <td>9</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-10-01</th>\n","      <td>9.50</td>\n","      <td>6.83</td>\n","      <td>10.50</td>\n","      <td>3.88</td>\n","      <td>6.13</td>\n","      <td>4.58</td>\n","      <td>4.21</td>\n","      <td>6.50</td>\n","      <td>6.38</td>\n","      <td>6.54</td>\n","      <td>10.63</td>\n","      <td>14.09</td>\n","      <td>1978-10-01</td>\n","      <td>10</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-11-01</th>\n","      <td>13.59</td>\n","      <td>16.75</td>\n","      <td>11.25</td>\n","      <td>7.08</td>\n","      <td>11.04</td>\n","      <td>8.33</td>\n","      <td>8.17</td>\n","      <td>11.29</td>\n","      <td>10.75</td>\n","      <td>11.25</td>\n","      <td>23.13</td>\n","      <td>25.00</td>\n","      <td>1978-11-01</td>\n","      <td>11</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1978-12-01</th>\n","      <td>21.29</td>\n","      <td>16.29</td>\n","      <td>24.04</td>\n","      <td>12.79</td>\n","      <td>18.21</td>\n","      <td>19.29</td>\n","      <td>21.54</td>\n","      <td>17.21</td>\n","      <td>16.71</td>\n","      <td>17.83</td>\n","      <td>17.75</td>\n","      <td>25.70</td>\n","      <td>1978-12-01</td>\n","      <td>12</td>\n","      <td>1978</td>\n","      <td>1</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>216 rows × 16 columns</p>\n","</div>"],"text/plain":["              RPT    VAL    ROS    KIL    SHA    BIR    DUB    CLA    MUL  \\\n","Yr_Mo_Dy                                                                    \n","1961-01-01  15.04  14.96  13.17   9.29    NaN   9.87  13.67  10.25  10.83   \n","1961-02-01  14.25  15.12   9.04   5.88  12.08   7.17  10.17   3.63   6.50   \n","1961-03-01  12.67  13.13  11.79   6.42   9.79   8.54  10.25  13.29    NaN   \n","1961-04-01   8.38   6.34   8.33   6.75   9.33   9.54  11.67   8.21  11.21   \n","1961-05-01  15.87  13.88  15.37   9.79  13.46  10.17   9.96  14.04   9.75   \n","1961-06-01  15.92   9.59  12.04   8.79  11.54   6.04   9.75   8.29   9.33   \n","1961-07-01   7.21   6.83   7.71   4.42   8.46   4.79   6.71   6.00   5.79   \n","1961-08-01   9.59   5.09   5.54   4.63   8.29   5.25   4.21   5.25   5.37   \n","1961-09-01   5.58   1.13   4.96   3.04   4.25   2.25   4.63   2.71   3.67   \n","1961-10-01  14.25  12.87   7.87   8.00  13.00   7.75   5.83   9.00   7.08   \n","1961-11-01  13.21  13.13  14.33   8.54  12.17  10.21  13.08  12.17  10.92   \n","1961-12-01   9.67   7.75   8.00   3.96   6.00   2.75   7.25   2.50   5.58   \n","1962-01-01   9.29   3.42  11.54   3.50   2.21   1.96  10.41   2.79   3.54   \n","1962-02-01  19.12  13.96  12.21  10.58  15.71  10.63  15.71  11.08  13.17   \n","1962-03-01   8.21   4.83   9.00   4.83   6.00   2.21   7.96   1.87   4.08   \n","1962-04-01  14.33  12.25  11.87  10.37  14.92  11.00  19.79  11.67  14.09   \n","1962-05-01   9.62   9.54   3.58   3.33   8.75   3.75   2.25   2.58   1.67   \n","1962-06-01   5.88   6.29   8.67   5.21   5.00   4.25   5.91   5.41   4.79   \n","1962-07-01   8.67   4.17   6.92   6.71   8.17   5.66  11.17   9.38   8.75   \n","1962-08-01   4.58   5.37   6.04   2.29   7.87   3.71   4.46   2.58   4.00   \n","1962-09-01  10.00  12.08  10.96   9.25   9.29   7.62   7.41   8.75   7.67   \n","1962-10-01  14.58   7.83  19.21  10.08  11.54   8.38  13.29  10.63   8.21   \n","1962-11-01  16.88  13.25  16.00   8.96  13.46  11.46  10.46  10.17  10.37   \n","1962-12-01  18.38  15.41  11.75   6.79  12.21   8.04   8.42  10.83   5.66   \n","1963-01-01  15.59  13.62  19.79   8.38  12.25  10.00  23.45  15.71  13.59   \n","1963-02-01  15.41   7.62  24.67  11.42   9.21   8.17  14.04   7.54   7.54   \n","1963-03-01  16.75  19.67  17.67   8.87  19.08  15.37  16.21  14.29  11.29   \n","1963-04-01  10.54   9.59  12.46   7.33   9.46   9.59  11.79  11.87   9.79   \n","1963-05-01  18.79  14.17  13.59  11.63  14.17  11.96  14.46  12.46  12.87   \n","1963-06-01  13.37   6.87  12.00   8.50  10.04   9.42  10.92  12.96  11.79   \n","...           ...    ...    ...    ...    ...    ...    ...    ...    ...   \n","1976-07-01   8.50   1.75   6.58   2.13   2.75   2.21   5.37   2.04   5.88   \n","1976-08-01  13.00   8.38   8.63   5.83  12.92   8.25  13.00   9.42  10.58   \n","1976-09-01  11.87  11.00   7.38   6.87   7.75   8.33  10.34   6.46  10.17   \n","1976-10-01  10.96   6.71  10.41   4.63   7.58   5.04   5.04   5.54   6.50   \n","1976-11-01  13.96  15.67  10.29   6.46  12.79   9.08  10.00   9.67  10.21   \n","1976-12-01  13.46  16.42   9.21   4.54  10.75   8.67  10.88   4.83   8.79   \n","1977-01-01  20.04  11.92  20.25   9.13   9.29   8.04  10.75   5.88   9.00   \n","1977-02-01  11.83   9.71  11.00   4.25   8.58   8.71   6.17   5.66   8.29   \n","1977-03-01   8.63  14.83  10.29   3.75   6.63   8.79   5.00   8.12   7.87   \n","1977-04-01  21.67  16.00  17.33  13.59  20.83  15.96  25.62  17.62  19.41   \n","1977-05-01   6.42   7.12   8.67   3.58   4.58   4.00   6.75   6.13   3.33   \n","1977-06-01   7.08   5.25   9.71   2.83   2.21   3.50   5.29   1.42   2.00   \n","1977-07-01  15.41  16.29  17.08   6.25  11.83  11.83  12.29  10.58  10.41   \n","1977-08-01   4.33   2.96   4.42   2.33   0.96   1.08   4.96   1.87   2.33   \n","1977-09-01  17.37  16.33  16.83   8.58  14.46  11.83  15.09  13.92  13.29   \n","1977-10-01  16.75  15.34  12.25   9.42  16.38  11.38  18.50  13.92  14.09   \n","1977-11-01  16.71  11.54  12.17   4.17   8.54   7.17  11.12   6.46   8.25   \n","1977-12-01  13.37  10.92  12.42   2.37   5.79   6.13   8.96   7.38   6.29   \n","1978-01-01   8.33   7.12   7.71   3.54   8.50   7.50  14.71  10.00  11.83   \n","1978-02-01  27.25  24.21  18.16  17.46  27.54  18.05  20.96  25.04  20.04   \n","1978-03-01  15.04   6.21  16.04   7.87   6.42   6.67  12.29   8.00  10.58   \n","1978-04-01   3.42   7.58   2.71   1.38   3.46   2.08   2.67   4.75   4.83   \n","1978-05-01  10.54  12.21   9.08   5.29  11.00  10.08  11.17  13.75  11.87   \n","1978-06-01  10.37  11.42   6.46   6.04  11.25   7.50   6.46   5.96   7.79   \n","1978-07-01  12.46  10.63  11.17   6.75  12.92   9.04  12.42   9.62  12.08   \n","1978-08-01  19.33  15.09  20.17   8.83  12.62  10.41   9.33  12.33   9.50   \n","1978-09-01   8.42   6.13   9.87   5.25   3.21   5.71   7.25   3.50   7.33   \n","1978-10-01   9.50   6.83  10.50   3.88   6.13   4.58   4.21   6.50   6.38   \n","1978-11-01  13.59  16.75  11.25   7.08  11.04   8.33   8.17  11.29  10.75   \n","1978-12-01  21.29  16.29  24.04  12.79  18.21  19.29  21.54  17.21  16.71   \n","\n","              CLO    BEL    MAL       date  month  year  day  \n","Yr_Mo_Dy                                                      \n","1961-01-01  12.58  18.50  15.04 1961-01-01      1  1961    1  \n","1961-02-01   5.50   9.17   8.00 1961-02-01      2  1961    1  \n","1961-03-01  12.21  20.62    NaN 1961-03-01      3  1961    1  \n","1961-04-01   6.46  11.96   7.17 1961-04-01      4  1961    1  \n","1961-05-01   9.92  18.63  11.12 1961-05-01      5  1961    1  \n","1961-06-01  10.34  10.67  12.12 1961-06-01      6  1961    1  \n","1961-07-01   7.96   6.96   8.71 1961-07-01      7  1961    1  \n","1961-08-01   5.41   8.38   9.08 1961-08-01      8  1961    1  \n","1961-09-01   6.00   4.79   5.41 1961-09-01      9  1961    1  \n","1961-10-01   5.29  11.79   4.04 1961-10-01     10  1961    1  \n","1961-11-01  13.54  20.17  20.04 1961-11-01     11  1961    1  \n","1961-12-01   5.58   7.79  11.17 1961-12-01     12  1961    1  \n","1962-01-01   5.17   4.38   7.92 1962-01-01      1  1962    1  \n","1962-02-01  12.62  17.67  22.71 1962-02-01      2  1962    1  \n","1962-03-01   3.92   4.08   5.41 1962-03-01      3  1962    1  \n","1962-04-01  15.46  16.62  23.58 1962-04-01      4  1962    1  \n","1962-05-01   2.37   7.29   3.25 1962-05-01      5  1962    1  \n","1962-06-01   9.25   5.25  10.71 1962-06-01      6  1962    1  \n","1962-07-01  11.12  10.25  17.08 1962-07-01      7  1962    1  \n","1962-08-01   4.79   7.21   7.46 1962-08-01      8  1962    1  \n","1962-09-01   9.62  14.58  11.92 1962-09-01      9  1962    1  \n","1962-10-01  12.92  18.05  18.12 1962-10-01     10  1962    1  \n","1962-11-01  13.21  14.83  15.16 1962-11-01     11  1962    1  \n","1962-12-01   9.08  11.50  11.50 1962-12-01     12  1962    1  \n","1963-01-01  14.37  17.58  34.13 1963-01-01      1  1963    1  \n","1963-02-01  10.08  10.17  17.67 1963-02-01      2  1963    1  \n","1963-03-01   9.21  19.92  19.79 1963-03-01      3  1963    1  \n","1963-04-01  10.71  13.37  18.21 1963-04-01      4  1963    1  \n","1963-05-01  13.96  15.29  21.62 1963-05-01      5  1963    1  \n","1963-06-01  11.04  10.92  13.67 1963-06-01      6  1963    1  \n","...           ...    ...    ...        ...    ...   ...  ...  \n","1976-07-01   4.50   4.96  10.63 1976-07-01      7  1976    1  \n","1976-08-01  11.34  14.21  20.25 1976-08-01      8  1976    1  \n","1976-09-01   9.29  12.75  19.55 1976-09-01      9  1976    1  \n","1976-10-01   3.92   6.79   5.00 1976-10-01     10  1976    1  \n","1976-11-01  11.63  23.09  21.96 1976-11-01     11  1976    1  \n","1976-12-01   5.91   8.83  13.67 1976-12-01     12  1976    1  \n","1977-01-01   9.00  14.88  25.70 1977-01-01      1  1977    1  \n","1977-02-01   7.58  11.71  16.50 1977-02-01      2  1977    1  \n","1977-03-01   6.42  13.54  13.67 1977-03-01      3  1977    1  \n","1977-04-01  20.67  24.37  30.09 1977-04-01      4  1977    1  \n","1977-05-01   4.50  19.21  12.38 1977-05-01      5  1977    1  \n","1977-06-01   0.92   5.21   5.63 1977-06-01      6  1977    1  \n","1977-07-01   7.21  17.37   7.83 1977-07-01      7  1977    1  \n","1977-08-01   2.04  10.50   9.83 1977-08-01      8  1977    1  \n","1977-09-01  13.88  23.29  25.17 1977-09-01      9  1977    1  \n","1977-10-01  14.46  22.34  29.67 1977-10-01     10  1977    1  \n","1977-11-01   6.21  11.04  15.63 1977-11-01     11  1977    1  \n","1977-12-01   5.71   8.54  12.42 1977-12-01     12  1977    1  \n","1978-01-01  10.00  15.09  20.46 1978-01-01      1  1978    1  \n","1978-02-01  17.50  27.71  21.12 1978-02-01      2  1978    1  \n","1978-03-01   9.33   5.41  17.00 1978-03-01      3  1978    1  \n","1978-04-01   1.67   7.33  13.67 1978-04-01      4  1978    1  \n","1978-05-01  11.79  12.87  27.16 1978-05-01      5  1978    1  \n","1978-06-01   5.46   5.50  10.41 1978-06-01      6  1978    1  \n","1978-07-01   8.04  14.04  16.17 1978-07-01      7  1978    1  \n","1978-08-01   9.92  15.75  18.00 1978-08-01      8  1978    1  \n","1978-09-01   6.50   7.62  15.96 1978-09-01      9  1978    1  \n","1978-10-01   6.54  10.63  14.09 1978-10-01     10  1978    1  \n","1978-11-01  11.25  23.13  25.00 1978-11-01     11  1978    1  \n","1978-12-01  17.83  17.75  25.70 1978-12-01     12  1978    1  \n","\n","[216 rows x 16 columns]"]},"execution_count":303,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","data.query('day == 1')"]},{"cell_type":"markdown","metadata":{"id":"7AD754718B3241A3A309AAEB9B2E0334","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"839083FB1C6B4E3689C25109E4A08240","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习7-可视化\n","## 探索泰坦尼克灾难数据"]},{"cell_type":"markdown","metadata":{"id":"1DF96941A4C0471A9F734C5A4EAB193D","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"384E16F6D67347A38DBD6121C2100686","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":304,"metadata":{"collapsed":false,"id":"0EE14A508D584CC2841C4B46265CAB84","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd\n","import matplotlib.pyplot as plt\n","import seaborn as sns\n","import numpy as np\n","\n","%matplotlib inline"]},{"cell_type":"markdown","metadata":{"id":"F15E185F66784DF1A8B2048650C9735B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 从以下地址导入数据"]},{"cell_type":"code","execution_count":36,"metadata":{"collapsed":false,"id":"F19BBFF584C04EEF844DD34E2C859A1A","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path7 = '../input/pandas_exercise/pandas_exercise/exercise_data/train.csv'  # train.csv"]},{"cell_type":"markdown","metadata":{"id":"15C1FBDB3DB8462C816F0701410E2A64","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将数据框命名为titanic"]},{"cell_type":"code","execution_count":306,"metadata":{"collapsed":false,"id":"C438CEC476EE4B3681ACE4AD0D4F5829","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>PassengerId</th>\n","      <th>Survived</th>\n","      <th>Pclass</th>\n","      <th>Name</th>\n","      <th>Sex</th>\n","      <th>Age</th>\n","      <th>SibSp</th>\n","      <th>Parch</th>\n","      <th>Ticket</th>\n","      <th>Fare</th>\n","      <th>Cabin</th>\n","      <th>Embarked</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>3</td>\n","      <td>Braund, Mr. Owen Harris</td>\n","      <td>male</td>\n","      <td>22.0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>A/5 21171</td>\n","      <td>7.2500</td>\n","      <td>NaN</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n","      <td>female</td>\n","      <td>38.0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>PC 17599</td>\n","      <td>71.2833</td>\n","      <td>C85</td>\n","      <td>C</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>3</td>\n","      <td>1</td>\n","      <td>3</td>\n","      <td>Heikkinen, Miss. Laina</td>\n","      <td>female</td>\n","      <td>26.0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>STON/O2. 3101282</td>\n","      <td>7.9250</td>\n","      <td>NaN</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4</td>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n","      <td>female</td>\n","      <td>35.0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>113803</td>\n","      <td>53.1000</td>\n","      <td>C123</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5</td>\n","      <td>0</td>\n","      <td>3</td>\n","      <td>Allen, Mr. William Henry</td>\n","      <td>male</td>\n","      <td>35.0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>373450</td>\n","      <td>8.0500</td>\n","      <td>NaN</td>\n","      <td>S</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   PassengerId  Survived  Pclass  \\\n","0            1         0       3   \n","1            2         1       1   \n","2            3         1       3   \n","3            4         1       1   \n","4            5         0       3   \n","\n","                                                Name     Sex   Age  SibSp  \\\n","0                            Braund, Mr. Owen Harris    male  22.0      1   \n","1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n","2                             Heikkinen, Miss. Laina  female  26.0      0   \n","3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n","4                           Allen, Mr. William Henry    male  35.0      0   \n","\n","   Parch            Ticket     Fare Cabin Embarked  \n","0      0         A/5 21171   7.2500   NaN        S  \n","1      0          PC 17599  71.2833   C85        C  \n","2      0  STON/O2. 3101282   7.9250   NaN        S  \n","3      0            113803  53.1000  C123        S  \n","4      0            373450   8.0500   NaN        S  "]},"execution_count":306,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","titanic = pd.read_csv(path7)\n","titanic.head()"]},{"cell_type":"markdown","metadata":{"id":"467E86F98EAA4C31966271C6531C4863","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 将PassengerId设置为索引"]},{"cell_type":"code","execution_count":307,"metadata":{"collapsed":false,"id":"925283942F0E4751B590F8867F72F6CD","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Survived</th>\n","      <th>Pclass</th>\n","      <th>Name</th>\n","      <th>Sex</th>\n","      <th>Age</th>\n","      <th>SibSp</th>\n","      <th>Parch</th>\n","      <th>Ticket</th>\n","      <th>Fare</th>\n","      <th>Cabin</th>\n","      <th>Embarked</th>\n","    </tr>\n","    <tr>\n","      <th>PassengerId</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1</th>\n","      <td>0</td>\n","      <td>3</td>\n","      <td>Braund, Mr. Owen Harris</td>\n","      <td>male</td>\n","      <td>22.0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>A/5 21171</td>\n","      <td>7.2500</td>\n","      <td>NaN</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n","      <td>female</td>\n","      <td>38.0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>PC 17599</td>\n","      <td>71.2833</td>\n","      <td>C85</td>\n","      <td>C</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>1</td>\n","      <td>3</td>\n","      <td>Heikkinen, Miss. Laina</td>\n","      <td>female</td>\n","      <td>26.0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>STON/O2. 3101282</td>\n","      <td>7.9250</td>\n","      <td>NaN</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>1</td>\n","      <td>1</td>\n","      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n","      <td>female</td>\n","      <td>35.0</td>\n","      <td>1</td>\n","      <td>0</td>\n","      <td>113803</td>\n","      <td>53.1000</td>\n","      <td>C123</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>0</td>\n","      <td>3</td>\n","      <td>Allen, Mr. William Henry</td>\n","      <td>male</td>\n","      <td>35.0</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>373450</td>\n","      <td>8.0500</td>\n","      <td>NaN</td>\n","      <td>S</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["             Survived  Pclass  \\\n","PassengerId                     \n","1                   0       3   \n","2                   1       1   \n","3                   1       3   \n","4                   1       1   \n","5                   0       3   \n","\n","                                                          Name     Sex   Age  \\\n","PassengerId                                                                    \n","1                                      Braund, Mr. Owen Harris    male  22.0   \n","2            Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0   \n","3                                       Heikkinen, Miss. Laina  female  26.0   \n","4                 Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0   \n","5                                     Allen, Mr. William Henry    male  35.0   \n","\n","             SibSp  Parch            Ticket     Fare Cabin Embarked  \n","PassengerId                                                          \n","1                1      0         A/5 21171   7.2500   NaN        S  \n","2                1      0          PC 17599  71.2833   C85        C  \n","3                0      0  STON/O2. 3101282   7.9250   NaN        S  \n","4                1      0            113803  53.1000  C123        S  \n","5                0      0            373450   8.0500   NaN        S  "]},"execution_count":307,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","titanic.set_index('PassengerId').head()"]},{"cell_type":"markdown","metadata":{"id":"93A81776B6374B5590DDDEF16CA70059","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 绘制一个展示男女乘客比例的扇形图"]},{"cell_type":"code","execution_count":308,"metadata":{"collapsed":false,"id":"29F113A209764A09A2B7E34F6D6D5418","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<img src=\"\n","\">"],"text/plain":["<Figure size 432x288 with 1 Axes>"]},"metadata":{},"output_type":"display_data"}],"source":["# 运行以下代码\n","# sum the instances of males and females\n","males = (titanic['Sex'] == 'male').sum()\n","females = (titanic['Sex'] == 'female').sum()\n","\n","# put them into a list called proportions\n","proportions = [males, females]\n","\n","# Create a pie chart\n","plt.pie(\n","    # using proportions\n","    proportions,\n","    \n","    # with the labels being officer names\n","    labels = ['Males', 'Females'],\n","    \n","    # with no shadows\n","    shadow = False,\n","    \n","    # with colors\n","    colors = ['blue','red'],\n","    \n","    # with one slide exploded out\n","    explode = (0.15 , 0),\n","    \n","    # with the start angle at 90%\n","    startangle = 90,\n","    \n","    # with the percent listed as a fraction\n","    autopct = '%1.1f%%'\n","    )\n","\n","# View the plot drop above\n","plt.axis('equal')\n","\n","# Set labels\n","plt.title(\"Sex Proportion\")\n","\n","# View the plot\n","plt.tight_layout()\n","plt.show()"]},{"cell_type":"markdown","metadata":{"id":"F097222642114F7FA9AF8960A7CEB856","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 绘制一个展示船票```Fare```, 与乘客年龄和性别的散点图"]},{"cell_type":"code","execution_count":309,"metadata":{"collapsed":false,"id":"751FFC45EDF842528A2E30354E36B56B","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["(-5, 85)"]},"execution_count":309,"metadata":{},"output_type":"execute_result"},{"data":{"text/html":["<img src=\"\n","\">"],"text/plain":["<Figure size 427.25x360 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["# 运行以下代码\n","# creates the plot using\n","lm = sns.lmplot(x = 'Age', y = 'Fare', data = titanic, hue = 'Sex', fit_reg=False)\n","\n","# set title\n","lm.set(title = 'Fare x Age')\n","\n","# get the axes object and tweak it\n","axes = lm.axes\n","axes[0,0].set_ylim(-5,)\n","axes[0,0].set_xlim(-5,85)"]},{"cell_type":"markdown","metadata":{"id":"871C006067394505A6E65270DF11228D","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 有多少人生还？"]},{"cell_type":"code","execution_count":310,"metadata":{"collapsed":false,"id":"FF9949C90E3B48328124B81A0E9C0A54","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["342"]},"execution_count":310,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","titanic.Survived.sum()"]},{"cell_type":"markdown","metadata":{"id":"7393B65FC11B4DB2829963507AA4C5D2","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 绘制一个展示船票价格的直方图"]},{"cell_type":"code","execution_count":311,"metadata":{"collapsed":false,"id":"5AEBDC9DF09E4CF9853842B23DBAA860","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<img src=\"\n","\">"],"text/plain":["<Figure size 432x288 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["# 运行以下代码\n","# sort the values from the top to the least value and slice the first 5 items\n","df = titanic.Fare.sort_values(ascending = False)\n","df\n","\n","# create bins interval using numpy\n","binsVal = np.arange(0,600,10)\n","binsVal\n","\n","# create the plot\n","plt.hist(df, bins = binsVal)\n","\n","# Set the title and labels\n","plt.xlabel('Fare')\n","plt.ylabel('Frequency')\n","plt.title('Fare Payed Histrogram')\n","\n","# show the plot\n","plt.show()"]},{"cell_type":"markdown","metadata":{"id":"1F8A3E77661D4ED59A4710CF6749CFD5","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"A79CDF7146C34FF68DFF54ED6CB7FFF2","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习8-创建数据框\n","## 探索Pokemon数据\n","![image description](https://cdn.kesci.com/images/lab_upload/1508342670584_84032.jpeg)"]},{"cell_type":"markdown","metadata":{"id":"6571E247FA0E43FB84E23F7F17EA277E","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"A34B6D463953438DACF85C7B7473EFD9","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":312,"metadata":{"collapsed":false,"id":"A8BB9F723C55413786B2FD98F6CB4726","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd"]},{"cell_type":"markdown","metadata":{"id":"D950D9C8945C442F833CAAD89A1A4467","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 创建一个数据字典"]},{"cell_type":"code","execution_count":313,"metadata":{"collapsed":false,"id":"30BEDCF6CAF7462E8FFC58ECC788D1CE","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","raw_data = {\"name\": ['Bulbasaur', 'Charmander','Squirtle','Caterpie'],\n","            \"evolution\": ['Ivysaur','Charmeleon','Wartortle','Metapod'],\n","            \"type\": ['grass', 'fire', 'water', 'bug'],\n","            \"hp\": [45, 39, 44, 45],\n","            \"pokedex\": ['yes', 'no','yes','no']                        \n","            }"]},{"cell_type":"markdown","metadata":{"id":"5DC4C80B21B94D219603DA918474A658","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将数据字典存为一个名叫pokemon的数据框中"]},{"cell_type":"code","execution_count":314,"metadata":{"collapsed":false,"id":"B547F7E999C843DE87A5764C379C83B7","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>evolution</th>\n","      <th>hp</th>\n","      <th>name</th>\n","      <th>pokedex</th>\n","      <th>type</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Ivysaur</td>\n","      <td>45</td>\n","      <td>Bulbasaur</td>\n","      <td>yes</td>\n","      <td>grass</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Charmeleon</td>\n","      <td>39</td>\n","      <td>Charmander</td>\n","      <td>no</td>\n","      <td>fire</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Wartortle</td>\n","      <td>44</td>\n","      <td>Squirtle</td>\n","      <td>yes</td>\n","      <td>water</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>Metapod</td>\n","      <td>45</td>\n","      <td>Caterpie</td>\n","      <td>no</td>\n","      <td>bug</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["    evolution  hp        name pokedex   type\n","0     Ivysaur  45   Bulbasaur     yes  grass\n","1  Charmeleon  39  Charmander      no   fire\n","2   Wartortle  44    Squirtle     yes  water\n","3     Metapod  45    Caterpie      no    bug"]},"execution_count":314,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pokemon = pd.DataFrame(raw_data)\n","pokemon.head()"]},{"cell_type":"markdown","metadata":{"id":"A51348F34F924DD3AAB0FDA0B23F7538","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 数据框的列排序是字母顺序，请重新修改为```name, type, hp, evolution, pokedex```这个顺序"]},{"cell_type":"code","execution_count":315,"metadata":{"collapsed":false,"id":"F9BFD66357A246458C99412659F043CD","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>name</th>\n","      <th>type</th>\n","      <th>hp</th>\n","      <th>evolution</th>\n","      <th>pokedex</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Bulbasaur</td>\n","      <td>grass</td>\n","      <td>45</td>\n","      <td>Ivysaur</td>\n","      <td>yes</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Charmander</td>\n","      <td>fire</td>\n","      <td>39</td>\n","      <td>Charmeleon</td>\n","      <td>no</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Squirtle</td>\n","      <td>water</td>\n","      <td>44</td>\n","      <td>Wartortle</td>\n","      <td>yes</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>Caterpie</td>\n","      <td>bug</td>\n","      <td>45</td>\n","      <td>Metapod</td>\n","      <td>no</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["         name   type  hp   evolution pokedex\n","0   Bulbasaur  grass  45     Ivysaur     yes\n","1  Charmander   fire  39  Charmeleon      no\n","2    Squirtle  water  44   Wartortle     yes\n","3    Caterpie    bug  45     Metapod      no"]},"execution_count":315,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pokemon = pokemon[['name', 'type', 'hp', 'evolution','pokedex']]\n","pokemon"]},{"cell_type":"markdown","metadata":{"id":"AEE5F48A61FC42B8B7C4FF3AD931F75B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 添加一个列```place```"]},{"cell_type":"code","execution_count":316,"metadata":{"collapsed":false,"id":"1266241FE80541819EA804078947F36E","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>name</th>\n","      <th>type</th>\n","      <th>hp</th>\n","      <th>evolution</th>\n","      <th>pokedex</th>\n","      <th>place</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>Bulbasaur</td>\n","      <td>grass</td>\n","      <td>45</td>\n","      <td>Ivysaur</td>\n","      <td>yes</td>\n","      <td>park</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Charmander</td>\n","      <td>fire</td>\n","      <td>39</td>\n","      <td>Charmeleon</td>\n","      <td>no</td>\n","      <td>street</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Squirtle</td>\n","      <td>water</td>\n","      <td>44</td>\n","      <td>Wartortle</td>\n","      <td>yes</td>\n","      <td>lake</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>Caterpie</td>\n","      <td>bug</td>\n","      <td>45</td>\n","      <td>Metapod</td>\n","      <td>no</td>\n","      <td>forest</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["         name   type  hp   evolution pokedex   place\n","0   Bulbasaur  grass  45     Ivysaur     yes    park\n","1  Charmander   fire  39  Charmeleon      no  street\n","2    Squirtle  water  44   Wartortle     yes    lake\n","3    Caterpie    bug  45     Metapod      no  forest"]},"execution_count":316,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pokemon['place'] = ['park','street','lake','forest']\n","pokemon"]},{"cell_type":"markdown","metadata":{"id":"89BA607ADFDD49238AED66C162437A98","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 查看每个列的数据类型"]},{"cell_type":"code","execution_count":317,"metadata":{"collapsed":false,"id":"4ED1CC286FAF4D2C99D0B405CE938110","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["name         object\n","type         object\n","hp            int64\n","evolution    object\n","pokedex      object\n","place        object\n","dtype: object"]},"execution_count":317,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pokemon.dtypes"]},{"cell_type":"markdown","metadata":{"id":"79E71C1A6C9F48FA98C69C1B6C8A8705","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"D12483ED25084A538006D15D572BE247","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习9-时间序列\n","## 探索Apple公司股价数据\n","![image description](https://cdn.kesci.com/images/lab_upload/1508342688865_7439.jpeg)"]},{"cell_type":"markdown","metadata":{"id":"010DC999472E4F6285E9BB2DD8D90F37","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"841A159C741942658AC5A2FBC92C8B57","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":318,"metadata":{"collapsed":false,"id":"C375B0EDB2394D0F9DE1BF6F42C18318","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd\n","import numpy as np\n","\n","# visualization\n","import matplotlib.pyplot as plt\n","\n","%matplotlib inline"]},{"cell_type":"markdown","metadata":{"id":"AA0086D4DF3C47E48A19B94ABAA17DE8","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 数据集地址"]},{"cell_type":"code","execution_count":37,"metadata":{"collapsed":false,"id":"892C693765AF4DF48B7D4C036B9D426B","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path9 = '../input/pandas_exercise/pandas_exercise/exercise_data/Apple_stock.csv'   # Apple_stock.csv"]},{"cell_type":"markdown","metadata":{"id":"EDFD5E34DB45409399520B6F743ED653","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 读取数据并存为一个名叫apple的数据框"]},{"cell_type":"code","execution_count":38,"metadata":{"collapsed":false,"id":"3DCDFFC7067249A586C211804FF33009","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Date</th>\n","      <th>Open</th>\n","      <th>High</th>\n","      <th>Low</th>\n","      <th>Close</th>\n","      <th>Volume</th>\n","      <th>Adj Close</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>2014-07-08</td>\n","      <td>96.27</td>\n","      <td>96.80</td>\n","      <td>93.92</td>\n","      <td>95.35</td>\n","      <td>65130000</td>\n","      <td>95.35</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2014-07-07</td>\n","      <td>94.14</td>\n","      <td>95.99</td>\n","      <td>94.10</td>\n","      <td>95.97</td>\n","      <td>56305400</td>\n","      <td>95.97</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>2014-07-03</td>\n","      <td>93.67</td>\n","      <td>94.10</td>\n","      <td>93.20</td>\n","      <td>94.03</td>\n","      <td>22891800</td>\n","      <td>94.03</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>2014-07-02</td>\n","      <td>93.87</td>\n","      <td>94.06</td>\n","      <td>93.09</td>\n","      <td>93.48</td>\n","      <td>28420900</td>\n","      <td>93.48</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>2014-07-01</td>\n","      <td>93.52</td>\n","      <td>94.07</td>\n","      <td>93.13</td>\n","      <td>93.52</td>\n","      <td>38170200</td>\n","      <td>93.52</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["         Date   Open   High    Low  Close    Volume  Adj Close\n","0  2014-07-08  96.27  96.80  93.92  95.35  65130000      95.35\n","1  2014-07-07  94.14  95.99  94.10  95.97  56305400      95.97\n","2  2014-07-03  93.67  94.10  93.20  94.03  22891800      94.03\n","3  2014-07-02  93.87  94.06  93.09  93.48  28420900      93.48\n","4  2014-07-01  93.52  94.07  93.13  93.52  38170200      93.52"]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple = pd.read_csv(path9)\n","apple.head()"]},{"cell_type":"markdown","metadata":{"id":"E9BBF6F963354A1BB499D87C283F37FF","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["\n","### 步骤4 查看每一列的数据类型"]},{"cell_type":"code","execution_count":321,"metadata":{"collapsed":false,"id":"25C3954C23FD4CBAA7424F0E8C8F3006","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["Date          object\n","Open         float64\n","High         float64\n","Low          float64\n","Close        float64\n","Volume         int64\n","Adj Close    float64\n","dtype: object"]},"execution_count":321,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple.dtypes"]},{"cell_type":"markdown","metadata":{"id":"43FB11ECE62A4D018E253B24A314E456","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 将```Date```这个列转换为```datetime```类型"]},{"cell_type":"code","execution_count":322,"metadata":{"collapsed":false,"id":"AFCD772304054FE08985879AA00D63DB","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["0   2014-07-08\n","1   2014-07-07\n","2   2014-07-03\n","3   2014-07-02\n","4   2014-07-01\n","Name: Date, dtype: datetime64[ns]"]},"execution_count":322,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple.Date = pd.to_datetime(apple.Date)\n","apple['Date'].head()"]},{"cell_type":"markdown","metadata":{"id":"6C7CB38E16724F6F8DF4571814EA0223","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 将```Date```设置为索引"]},{"cell_type":"code","execution_count":323,"metadata":{"collapsed":false,"id":"92FCBBEF13184AD783156A8F09DC94A9","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Open</th>\n","      <th>High</th>\n","      <th>Low</th>\n","      <th>Close</th>\n","      <th>Volume</th>\n","      <th>Adj Close</th>\n","    </tr>\n","    <tr>\n","      <th>Date</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>2014-07-08</th>\n","      <td>96.27</td>\n","      <td>96.80</td>\n","      <td>93.92</td>\n","      <td>95.35</td>\n","      <td>65130000</td>\n","      <td>95.35</td>\n","    </tr>\n","    <tr>\n","      <th>2014-07-07</th>\n","      <td>94.14</td>\n","      <td>95.99</td>\n","      <td>94.10</td>\n","      <td>95.97</td>\n","      <td>56305400</td>\n","      <td>95.97</td>\n","    </tr>\n","    <tr>\n","      <th>2014-07-03</th>\n","      <td>93.67</td>\n","      <td>94.10</td>\n","      <td>93.20</td>\n","      <td>94.03</td>\n","      <td>22891800</td>\n","      <td>94.03</td>\n","    </tr>\n","    <tr>\n","      <th>2014-07-02</th>\n","      <td>93.87</td>\n","      <td>94.06</td>\n","      <td>93.09</td>\n","      <td>93.48</td>\n","      <td>28420900</td>\n","      <td>93.48</td>\n","    </tr>\n","    <tr>\n","      <th>2014-07-01</th>\n","      <td>93.52</td>\n","      <td>94.07</td>\n","      <td>93.13</td>\n","      <td>93.52</td>\n","      <td>38170200</td>\n","      <td>93.52</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["             Open   High    Low  Close    Volume  Adj Close\n","Date                                                       \n","2014-07-08  96.27  96.80  93.92  95.35  65130000      95.35\n","2014-07-07  94.14  95.99  94.10  95.97  56305400      95.97\n","2014-07-03  93.67  94.10  93.20  94.03  22891800      94.03\n","2014-07-02  93.87  94.06  93.09  93.48  28420900      93.48\n","2014-07-01  93.52  94.07  93.13  93.52  38170200      93.52"]},"execution_count":323,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple = apple.set_index('Date')\n","apple.head()"]},{"cell_type":"markdown","metadata":{"id":"04BE78E24B7E4E60AC86281DEB4288C4","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 有重复的日期吗？"]},{"cell_type":"code","execution_count":324,"metadata":{"collapsed":false,"id":"21C64EAFF83F4A078B1BACC3FD070F66","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["True"]},"execution_count":324,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple.index.is_unique"]},{"cell_type":"markdown","metadata":{"id":"129DB8AED2054826AB2DDCF7C90B9788","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 将index设置为升序"]},{"cell_type":"code","execution_count":325,"metadata":{"collapsed":false,"id":"5348053ADAF1449F870581BD8130F266","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Open</th>\n","      <th>High</th>\n","      <th>Low</th>\n","      <th>Close</th>\n","      <th>Volume</th>\n","      <th>Adj Close</th>\n","    </tr>\n","    <tr>\n","      <th>Date</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1980-12-12</th>\n","      <td>28.75</td>\n","      <td>28.87</td>\n","      <td>28.75</td>\n","      <td>28.75</td>\n","      <td>117258400</td>\n","      <td>0.45</td>\n","    </tr>\n","    <tr>\n","      <th>1980-12-15</th>\n","      <td>27.38</td>\n","      <td>27.38</td>\n","      <td>27.25</td>\n","      <td>27.25</td>\n","      <td>43971200</td>\n","      <td>0.42</td>\n","    </tr>\n","    <tr>\n","      <th>1980-12-16</th>\n","      <td>25.37</td>\n","      <td>25.37</td>\n","      <td>25.25</td>\n","      <td>25.25</td>\n","      <td>26432000</td>\n","      <td>0.39</td>\n","    </tr>\n","    <tr>\n","      <th>1980-12-17</th>\n","      <td>25.87</td>\n","      <td>26.00</td>\n","      <td>25.87</td>\n","      <td>25.87</td>\n","      <td>21610400</td>\n","      <td>0.40</td>\n","    </tr>\n","    <tr>\n","      <th>1980-12-18</th>\n","      <td>26.63</td>\n","      <td>26.75</td>\n","      <td>26.63</td>\n","      <td>26.63</td>\n","      <td>18362400</td>\n","      <td>0.41</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["             Open   High    Low  Close     Volume  Adj Close\n","Date                                                        \n","1980-12-12  28.75  28.87  28.75  28.75  117258400       0.45\n","1980-12-15  27.38  27.38  27.25  27.25   43971200       0.42\n","1980-12-16  25.37  25.37  25.25  25.25   26432000       0.39\n","1980-12-17  25.87  26.00  25.87  25.87   21610400       0.40\n","1980-12-18  26.63  26.75  26.63  26.63   18362400       0.41"]},"execution_count":325,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple.sort_index(ascending = True).head()"]},{"cell_type":"markdown","metadata":{"id":"E8712B6D34904D38AB1CF00A864C70CE","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤9 找到每个月的最后一个交易日(business day)"]},{"cell_type":"code","execution_count":326,"metadata":{"collapsed":false,"id":"68ACA44BC1714EE68D510D010741A310","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["/opt/conda/lib/python3.5/site-packages/ipykernel_launcher.py:3: FutureWarning: \n",".resample() is now a deferred operation\n","You called head(...) on this deferred object which materialized it into a dataframe\n","by implicitly taking the mean.  Use .resample(...).mean() instead\n","  This is separate from the ipykernel package so we can avoid doing imports until\n"]},{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Open</th>\n","      <th>High</th>\n","      <th>Low</th>\n","      <th>Close</th>\n","      <th>Volume</th>\n","      <th>Adj Close</th>\n","    </tr>\n","    <tr>\n","      <th>Date</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>1980-12-31</th>\n","      <td>30.481538</td>\n","      <td>30.567692</td>\n","      <td>30.443077</td>\n","      <td>30.443077</td>\n","      <td>2.586252e+07</td>\n","      <td>0.473077</td>\n","    </tr>\n","    <tr>\n","      <th>1981-01-30</th>\n","      <td>31.754762</td>\n","      <td>31.826667</td>\n","      <td>31.654762</td>\n","      <td>31.654762</td>\n","      <td>7.249867e+06</td>\n","      <td>0.493810</td>\n","    </tr>\n","    <tr>\n","      <th>1981-02-27</th>\n","      <td>26.480000</td>\n","      <td>26.572105</td>\n","      <td>26.407895</td>\n","      <td>26.407895</td>\n","      <td>4.231832e+06</td>\n","      <td>0.411053</td>\n","    </tr>\n","    <tr>\n","      <th>1981-03-31</th>\n","      <td>24.937727</td>\n","      <td>25.016818</td>\n","      <td>24.836364</td>\n","      <td>24.836364</td>\n","      <td>7.962691e+06</td>\n","      <td>0.387727</td>\n","    </tr>\n","    <tr>\n","      <th>1981-04-30</th>\n","      <td>27.286667</td>\n","      <td>27.368095</td>\n","      <td>27.227143</td>\n","      <td>27.227143</td>\n","      <td>6.392000e+06</td>\n","      <td>0.423333</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["                 Open       High        Low      Close        Volume  \\\n","Date                                                                   \n","1980-12-31  30.481538  30.567692  30.443077  30.443077  2.586252e+07   \n","1981-01-30  31.754762  31.826667  31.654762  31.654762  7.249867e+06   \n","1981-02-27  26.480000  26.572105  26.407895  26.407895  4.231832e+06   \n","1981-03-31  24.937727  25.016818  24.836364  24.836364  7.962691e+06   \n","1981-04-30  27.286667  27.368095  27.227143  27.227143  6.392000e+06   \n","\n","            Adj Close  \n","Date                   \n","1980-12-31   0.473077  \n","1981-01-30   0.493810  \n","1981-02-27   0.411053  \n","1981-03-31   0.387727  \n","1981-04-30   0.423333  "]},"execution_count":326,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple_month = apple.resample('BM')\n","apple_month.head()"]},{"cell_type":"markdown","metadata":{"id":"C0C619B0380944EB8E0BE33169FF1CC6","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤10 数据集中最早的日期和最晚的日期相差多少天？"]},{"cell_type":"code","execution_count":327,"metadata":{"collapsed":false,"id":"4979EADDA15A41A0889BA622E2CD29AD","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["12261"]},"execution_count":327,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","(apple.index.max() - apple.index.min()).days"]},{"cell_type":"markdown","metadata":{"id":"3956CFCA4F6D4ADA809C08E6CE84D09A","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤11 在数据中一共有多少个月？"]},{"cell_type":"code","execution_count":328,"metadata":{"collapsed":false,"id":"EA7576FD16F746218BB6D16F9CA55B9D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["404"]},"execution_count":328,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","apple_months = apple.resample('BM').mean()\n","len(apple_months.index)"]},{"cell_type":"markdown","metadata":{"id":"6540965C29F34777862F9444993802B3","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤12 按照时间顺序可视化```Adj Close```值"]},{"cell_type":"code","execution_count":329,"metadata":{"collapsed":false,"id":"9B8093F53C6A420F97817B15B11B1909","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<img src=\"\n","\">"],"text/plain":["<Figure size 972x648 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["# 运行以下代码\n","# makes the plot and assign it to a variable\n","appl_open = apple['Adj Close'].plot(title = \"Apple Stock\")\n","\n","# changes the size of the graph\n","fig = appl_open.get_figure()\n","fig.set_size_inches(13.5, 9)"]},{"cell_type":"markdown","metadata":{"id":"77A29AE2277B4B888DA85F4B8004B692","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"6D868A80324047C48A462D078ACB33B0","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 练习10-删除数据\n","## 探索Iris纸鸢花数据"]},{"cell_type":"markdown","metadata":{"id":"53FA7EB229D049A38772245D34B021BB","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤1 导入必要的库"]},{"cell_type":"code","execution_count":330,"metadata":{"collapsed":false,"id":"8174631DDE094F2291974609325E2270","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","import pandas as pd"]},{"cell_type":"markdown","metadata":{"id":"F1742B17F6194C51A6424499292A4E42","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤2 数据集地址"]},{"cell_type":"code","execution_count":40,"metadata":{"collapsed":false,"id":"DE715394D0404C638290A313DCB45B32","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[],"source":["# 运行以下代码\n","path10 ='../input/pandas_exercise/pandas_exercise/exercise_data/iris.csv'   # iris.csv"]},{"cell_type":"markdown","metadata":{"id":"C7AB4912446F42168B615F4DD32A7CB3","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤3 将数据集存成变量```iris```"]},{"cell_type":"code","execution_count":41,"metadata":{"collapsed":false,"id":"116FC6EABA704E5989C15ACB34AA8624","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>5.1</th>\n","      <th>3.5</th>\n","      <th>1.4</th>\n","      <th>0.2</th>\n","      <th>Iris-setosa</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>4.9</td>\n","      <td>3.0</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>4.7</td>\n","      <td>3.2</td>\n","      <td>1.3</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.4</td>\n","      <td>3.9</td>\n","      <td>1.7</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   5.1  3.5  1.4  0.2  Iris-setosa\n","0  4.9  3.0  1.4  0.2  Iris-setosa\n","1  4.7  3.2  1.3  0.2  Iris-setosa\n","2  4.6  3.1  1.5  0.2  Iris-setosa\n","3  5.0  3.6  1.4  0.2  Iris-setosa\n","4  5.4  3.9  1.7  0.4  Iris-setosa"]},"execution_count":null,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","iris = pd.read_csv(path10)\n","iris.head()"]},{"cell_type":"markdown","metadata":{"id":"658B4FE4FC9C4DBC8EACACB9C647E0CE","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤4 创建数据框的列名称"]},{"cell_type":"code","execution_count":333,"metadata":{"collapsed":false,"id":"5344A56EC22C49558C91E9A4BDA34B7E","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>sepal_length</th>\n","      <th>sepal_width</th>\n","      <th>petal_length</th>\n","      <th>petal_width</th>\n","      <th>class</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>5.1</td>\n","      <td>3.5</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>4.9</td>\n","      <td>3.0</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>4.7</td>\n","      <td>3.2</td>\n","      <td>1.3</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   sepal_length  sepal_width  petal_length  petal_width        class\n","0           5.1          3.5           1.4          0.2  Iris-setosa\n","1           4.9          3.0           1.4          0.2  Iris-setosa\n","2           4.7          3.2           1.3          0.2  Iris-setosa\n","3           4.6          3.1           1.5          0.2  Iris-setosa\n","4           5.0          3.6           1.4          0.2  Iris-setosa"]},"execution_count":333,"metadata":{},"output_type":"execute_result"}],"source":["iris = pd.read_csv(path10,names = ['sepal_length','sepal_width', 'petal_length', 'petal_width', 'class'])\n","iris.head()"]},{"cell_type":"markdown","metadata":{"id":"13CDAB74062843E2815364D365A03417","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤5 数据框中有缺失值吗？"]},{"cell_type":"code","execution_count":334,"metadata":{"collapsed":false,"id":"6F227576DD6B49548B9BBBA0FA8430AF","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/plain":["sepal_length    0\n","sepal_width     0\n","petal_length    0\n","petal_width     0\n","class           0\n","dtype: int64"]},"execution_count":334,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","pd.isnull(iris).sum()"]},{"cell_type":"markdown","metadata":{"id":"62EEA41BE65641F4AEE510E8C90EC1A4","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤6 将列```petal_length```的第10到19行设置为缺失值"]},{"cell_type":"code","execution_count":335,"metadata":{"collapsed":false,"id":"620281C521564E2E86D3C5E35555B5EE","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>sepal_length</th>\n","      <th>sepal_width</th>\n","      <th>petal_length</th>\n","      <th>petal_width</th>\n","      <th>class</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>5.1</td>\n","      <td>3.5</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>4.9</td>\n","      <td>3.0</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>4.7</td>\n","      <td>3.2</td>\n","      <td>1.3</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>5.4</td>\n","      <td>3.9</td>\n","      <td>1.7</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>4.6</td>\n","      <td>3.4</td>\n","      <td>1.4</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>5.0</td>\n","      <td>3.4</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>4.4</td>\n","      <td>2.9</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>4.9</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.1</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>5.4</td>\n","      <td>3.7</td>\n","      <td>NaN</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>4.8</td>\n","      <td>3.4</td>\n","      <td>NaN</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>4.8</td>\n","      <td>3.0</td>\n","      <td>NaN</td>\n","      <td>0.1</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>4.3</td>\n","      <td>3.0</td>\n","      <td>NaN</td>\n","      <td>0.1</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>14</th>\n","      <td>5.8</td>\n","      <td>4.0</td>\n","      <td>NaN</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>15</th>\n","      <td>5.7</td>\n","      <td>4.4</td>\n","      <td>NaN</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>16</th>\n","      <td>5.4</td>\n","      <td>3.9</td>\n","      <td>NaN</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>17</th>\n","      <td>5.1</td>\n","      <td>3.5</td>\n","      <td>NaN</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>18</th>\n","      <td>5.7</td>\n","      <td>3.8</td>\n","      <td>NaN</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>19</th>\n","      <td>5.1</td>\n","      <td>3.8</td>\n","      <td>NaN</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["    sepal_length  sepal_width  petal_length  petal_width        class\n","0            5.1          3.5           1.4          0.2  Iris-setosa\n","1            4.9          3.0           1.4          0.2  Iris-setosa\n","2            4.7          3.2           1.3          0.2  Iris-setosa\n","3            4.6          3.1           1.5          0.2  Iris-setosa\n","4            5.0          3.6           1.4          0.2  Iris-setosa\n","5            5.4          3.9           1.7          0.4  Iris-setosa\n","6            4.6          3.4           1.4          0.3  Iris-setosa\n","7            5.0          3.4           1.5          0.2  Iris-setosa\n","8            4.4          2.9           1.4          0.2  Iris-setosa\n","9            4.9          3.1           1.5          0.1  Iris-setosa\n","10           5.4          3.7           NaN          0.2  Iris-setosa\n","11           4.8          3.4           NaN          0.2  Iris-setosa\n","12           4.8          3.0           NaN          0.1  Iris-setosa\n","13           4.3          3.0           NaN          0.1  Iris-setosa\n","14           5.8          4.0           NaN          0.2  Iris-setosa\n","15           5.7          4.4           NaN          0.4  Iris-setosa\n","16           5.4          3.9           NaN          0.4  Iris-setosa\n","17           5.1          3.5           NaN          0.3  Iris-setosa\n","18           5.7          3.8           NaN          0.3  Iris-setosa\n","19           5.1          3.8           NaN          0.3  Iris-setosa"]},"execution_count":335,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","iris.iloc[10:20,2:3] = np.nan\n","iris.head(20)"]},{"cell_type":"markdown","metadata":{"id":"AA39C79B25D54E9880D43E93797210ED","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤7 将缺失值全部替换为1.0"]},{"cell_type":"code","execution_count":336,"metadata":{"collapsed":false,"id":"D91501E46FA64A818BA70DDB76CB9CBE","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>sepal_length</th>\n","      <th>sepal_width</th>\n","      <th>petal_length</th>\n","      <th>petal_width</th>\n","      <th>class</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>5.1</td>\n","      <td>3.5</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>4.9</td>\n","      <td>3.0</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>4.7</td>\n","      <td>3.2</td>\n","      <td>1.3</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>5.4</td>\n","      <td>3.9</td>\n","      <td>1.7</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>4.6</td>\n","      <td>3.4</td>\n","      <td>1.4</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>5.0</td>\n","      <td>3.4</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>4.4</td>\n","      <td>2.9</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>4.9</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.1</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>5.4</td>\n","      <td>3.7</td>\n","      <td>1.0</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>4.8</td>\n","      <td>3.4</td>\n","      <td>1.0</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>12</th>\n","      <td>4.8</td>\n","      <td>3.0</td>\n","      <td>1.0</td>\n","      <td>0.1</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>13</th>\n","      <td>4.3</td>\n","      <td>3.0</td>\n","      <td>1.0</td>\n","      <td>0.1</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>14</th>\n","      <td>5.8</td>\n","      <td>4.0</td>\n","      <td>1.0</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>15</th>\n","      <td>5.7</td>\n","      <td>4.4</td>\n","      <td>1.0</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>16</th>\n","      <td>5.4</td>\n","      <td>3.9</td>\n","      <td>1.0</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>17</th>\n","      <td>5.1</td>\n","      <td>3.5</td>\n","      <td>1.0</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>18</th>\n","      <td>5.7</td>\n","      <td>3.8</td>\n","      <td>1.0</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>19</th>\n","      <td>5.1</td>\n","      <td>3.8</td>\n","      <td>1.0</td>\n","      <td>0.3</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>20</th>\n","      <td>5.4</td>\n","      <td>3.4</td>\n","      <td>1.7</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>21</th>\n","      <td>5.1</td>\n","      <td>3.7</td>\n","      <td>1.5</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>22</th>\n","      <td>4.6</td>\n","      <td>3.6</td>\n","      <td>1.0</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>23</th>\n","      <td>5.1</td>\n","      <td>3.3</td>\n","      <td>1.7</td>\n","      <td>0.5</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>24</th>\n","      <td>4.8</td>\n","      <td>3.4</td>\n","      <td>1.9</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>25</th>\n","      <td>5.0</td>\n","      <td>3.0</td>\n","      <td>1.6</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>26</th>\n","      <td>5.0</td>\n","      <td>3.4</td>\n","      <td>1.6</td>\n","      <td>0.4</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>27</th>\n","      <td>5.2</td>\n","      <td>3.5</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>28</th>\n","      <td>5.2</td>\n","      <td>3.4</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>29</th>\n","      <td>4.7</td>\n","      <td>3.2</td>\n","      <td>1.6</td>\n","      <td>0.2</td>\n","      <td>Iris-setosa</td>\n","    </tr>\n","    <tr>\n","      <th>...</th>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","    </tr>\n","    <tr>\n","      <th>120</th>\n","      <td>6.9</td>\n","      <td>3.2</td>\n","      <td>5.7</td>\n","      <td>2.3</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>121</th>\n","      <td>5.6</td>\n","      <td>2.8</td>\n","      <td>4.9</td>\n","      <td>2.0</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>122</th>\n","      <td>7.7</td>\n","      <td>2.8</td>\n","      <td>6.7</td>\n","      <td>2.0</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>123</th>\n","      <td>6.3</td>\n","      <td>2.7</td>\n","      <td>4.9</td>\n","      <td>1.8</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>124</th>\n","      <td>6.7</td>\n","      <td>3.3</td>\n","      <td>5.7</td>\n","      <td>2.1</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>125</th>\n","      <td>7.2</td>\n","      <td>3.2</td>\n","      <td>6.0</td>\n","      <td>1.8</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>126</th>\n","      <td>6.2</td>\n","      <td>2.8</td>\n","      <td>4.8</td>\n","      <td>1.8</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>127</th>\n","      <td>6.1</td>\n","      <td>3.0</td>\n","      <td>4.9</td>\n","      <td>1.8</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>128</th>\n","      <td>6.4</td>\n","      <td>2.8</td>\n","      <td>5.6</td>\n","      <td>2.1</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>129</th>\n","      <td>7.2</td>\n","      <td>3.0</td>\n","      <td>5.8</td>\n","      <td>1.6</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>130</th>\n","      <td>7.4</td>\n","      <td>2.8</td>\n","      <td>6.1</td>\n","      <td>1.9</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>131</th>\n","      <td>7.9</td>\n","      <td>3.8</td>\n","      <td>6.4</td>\n","      <td>2.0</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>132</th>\n","      <td>6.4</td>\n","      <td>2.8</td>\n","      <td>5.6</td>\n","      <td>2.2</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>133</th>\n","      <td>6.3</td>\n","      <td>2.8</td>\n","      <td>5.1</td>\n","      <td>1.5</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>134</th>\n","      <td>6.1</td>\n","      <td>2.6</td>\n","      <td>5.6</td>\n","      <td>1.4</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>135</th>\n","      <td>7.7</td>\n","      <td>3.0</td>\n","      <td>6.1</td>\n","      <td>2.3</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>136</th>\n","      <td>6.3</td>\n","      <td>3.4</td>\n","      <td>5.6</td>\n","      <td>2.4</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>137</th>\n","      <td>6.4</td>\n","      <td>3.1</td>\n","      <td>5.5</td>\n","      <td>1.8</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>138</th>\n","      <td>6.0</td>\n","      <td>3.0</td>\n","      <td>4.8</td>\n","      <td>1.8</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>139</th>\n","      <td>6.9</td>\n","      <td>3.1</td>\n","      <td>5.4</td>\n","      <td>2.1</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>140</th>\n","      <td>6.7</td>\n","      <td>3.1</td>\n","      <td>5.6</td>\n","      <td>2.4</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>141</th>\n","      <td>6.9</td>\n","      <td>3.1</td>\n","      <td>5.1</td>\n","      <td>2.3</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>142</th>\n","      <td>5.8</td>\n","      <td>2.7</td>\n","      <td>5.1</td>\n","      <td>1.9</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>143</th>\n","      <td>6.8</td>\n","      <td>3.2</td>\n","      <td>5.9</td>\n","      <td>2.3</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>144</th>\n","      <td>6.7</td>\n","      <td>3.3</td>\n","      <td>5.7</td>\n","      <td>2.5</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>145</th>\n","      <td>6.7</td>\n","      <td>3.0</td>\n","      <td>5.2</td>\n","      <td>2.3</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>146</th>\n","      <td>6.3</td>\n","      <td>2.5</td>\n","      <td>5.0</td>\n","      <td>1.9</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>147</th>\n","      <td>6.5</td>\n","      <td>3.0</td>\n","      <td>5.2</td>\n","      <td>2.0</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>148</th>\n","      <td>6.2</td>\n","      <td>3.4</td>\n","      <td>5.4</td>\n","      <td>2.3</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","    <tr>\n","      <th>149</th>\n","      <td>5.9</td>\n","      <td>3.0</td>\n","      <td>5.1</td>\n","      <td>1.8</td>\n","      <td>Iris-virginica</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>150 rows × 5 columns</p>\n","</div>"],"text/plain":["     sepal_length  sepal_width  petal_length  petal_width           class\n","0             5.1          3.5           1.4          0.2     Iris-setosa\n","1             4.9          3.0           1.4          0.2     Iris-setosa\n","2             4.7          3.2           1.3          0.2     Iris-setosa\n","3             4.6          3.1           1.5          0.2     Iris-setosa\n","4             5.0          3.6           1.4          0.2     Iris-setosa\n","5             5.4          3.9           1.7          0.4     Iris-setosa\n","6             4.6          3.4           1.4          0.3     Iris-setosa\n","7             5.0          3.4           1.5          0.2     Iris-setosa\n","8             4.4          2.9           1.4          0.2     Iris-setosa\n","9             4.9          3.1           1.5          0.1     Iris-setosa\n","10            5.4          3.7           1.0          0.2     Iris-setosa\n","11            4.8          3.4           1.0          0.2     Iris-setosa\n","12            4.8          3.0           1.0          0.1     Iris-setosa\n","13            4.3          3.0           1.0          0.1     Iris-setosa\n","14            5.8          4.0           1.0          0.2     Iris-setosa\n","15            5.7          4.4           1.0          0.4     Iris-setosa\n","16            5.4          3.9           1.0          0.4     Iris-setosa\n","17            5.1          3.5           1.0          0.3     Iris-setosa\n","18            5.7          3.8           1.0          0.3     Iris-setosa\n","19            5.1          3.8           1.0          0.3     Iris-setosa\n","20            5.4          3.4           1.7          0.2     Iris-setosa\n","21            5.1          3.7           1.5          0.4     Iris-setosa\n","22            4.6          3.6           1.0          0.2     Iris-setosa\n","23            5.1          3.3           1.7          0.5     Iris-setosa\n","24            4.8          3.4           1.9          0.2     Iris-setosa\n","25            5.0          3.0           1.6          0.2     Iris-setosa\n","26            5.0          3.4           1.6          0.4     Iris-setosa\n","27            5.2          3.5           1.5          0.2     Iris-setosa\n","28            5.2          3.4           1.4          0.2     Iris-setosa\n","29            4.7          3.2           1.6          0.2     Iris-setosa\n","..            ...          ...           ...          ...             ...\n","120           6.9          3.2           5.7          2.3  Iris-virginica\n","121           5.6          2.8           4.9          2.0  Iris-virginica\n","122           7.7          2.8           6.7          2.0  Iris-virginica\n","123           6.3          2.7           4.9          1.8  Iris-virginica\n","124           6.7          3.3           5.7          2.1  Iris-virginica\n","125           7.2          3.2           6.0          1.8  Iris-virginica\n","126           6.2          2.8           4.8          1.8  Iris-virginica\n","127           6.1          3.0           4.9          1.8  Iris-virginica\n","128           6.4          2.8           5.6          2.1  Iris-virginica\n","129           7.2          3.0           5.8          1.6  Iris-virginica\n","130           7.4          2.8           6.1          1.9  Iris-virginica\n","131           7.9          3.8           6.4          2.0  Iris-virginica\n","132           6.4          2.8           5.6          2.2  Iris-virginica\n","133           6.3          2.8           5.1          1.5  Iris-virginica\n","134           6.1          2.6           5.6          1.4  Iris-virginica\n","135           7.7          3.0           6.1          2.3  Iris-virginica\n","136           6.3          3.4           5.6          2.4  Iris-virginica\n","137           6.4          3.1           5.5          1.8  Iris-virginica\n","138           6.0          3.0           4.8          1.8  Iris-virginica\n","139           6.9          3.1           5.4          2.1  Iris-virginica\n","140           6.7          3.1           5.6          2.4  Iris-virginica\n","141           6.9          3.1           5.1          2.3  Iris-virginica\n","142           5.8          2.7           5.1          1.9  Iris-virginica\n","143           6.8          3.2           5.9          2.3  Iris-virginica\n","144           6.7          3.3           5.7          2.5  Iris-virginica\n","145           6.7          3.0           5.2          2.3  Iris-virginica\n","146           6.3          2.5           5.0          1.9  Iris-virginica\n","147           6.5          3.0           5.2          2.0  Iris-virginica\n","148           6.2          3.4           5.4          2.3  Iris-virginica\n","149           5.9          3.0           5.1          1.8  Iris-virginica\n","\n","[150 rows x 5 columns]"]},"execution_count":336,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","iris.petal_length.fillna(1, inplace = True)\n","iris"]},{"cell_type":"markdown","metadata":{"id":"509A66D663A047E2AA506229CFB3FA7B","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤8 删除列```class```"]},{"cell_type":"code","execution_count":337,"metadata":{"collapsed":false,"id":"BC3EC77223684A4E80701EC97976621C","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>sepal_length</th>\n","      <th>sepal_width</th>\n","      <th>petal_length</th>\n","      <th>petal_width</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>5.1</td>\n","      <td>3.5</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>4.9</td>\n","      <td>3.0</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>4.7</td>\n","      <td>3.2</td>\n","      <td>1.3</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   sepal_length  sepal_width  petal_length  petal_width\n","0           5.1          3.5           1.4          0.2\n","1           4.9          3.0           1.4          0.2\n","2           4.7          3.2           1.3          0.2\n","3           4.6          3.1           1.5          0.2\n","4           5.0          3.6           1.4          0.2"]},"execution_count":337,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","del iris['class']\n","iris.head()"]},{"cell_type":"markdown","metadata":{"id":"39FBC2D9C9684D07A30C63A77A3A060C","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤9 将数据框前三行设置为缺失值"]},{"cell_type":"code","execution_count":338,"metadata":{"collapsed":false,"id":"DBB8AAF3AB2D48528C60103D85588A90","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>sepal_length</th>\n","      <th>sepal_width</th>\n","      <th>petal_length</th>\n","      <th>petal_width</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   sepal_length  sepal_width  petal_length  petal_width\n","0           NaN          NaN           NaN          NaN\n","1           NaN          NaN           NaN          NaN\n","2           NaN          NaN           NaN          NaN\n","3           4.6          3.1           1.5          0.2\n","4           5.0          3.6           1.4          0.2"]},"execution_count":338,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","iris.iloc[0:3 ,:] = np.nan\n","iris.head()"]},{"cell_type":"markdown","metadata":{"id":"2CBD5365BAEE44D1886D1BB140BA0464","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤10 删除有缺失值的行"]},{"cell_type":"code","execution_count":339,"metadata":{"collapsed":false,"id":"4316CF96749B47E9952009EEF996FCF5","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>sepal_length</th>\n","      <th>sepal_width</th>\n","      <th>petal_length</th>\n","      <th>petal_width</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>3</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>5.4</td>\n","      <td>3.9</td>\n","      <td>1.7</td>\n","      <td>0.4</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>4.6</td>\n","      <td>3.4</td>\n","      <td>1.4</td>\n","      <td>0.3</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>5.0</td>\n","      <td>3.4</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   sepal_length  sepal_width  petal_length  petal_width\n","3           4.6          3.1           1.5          0.2\n","4           5.0          3.6           1.4          0.2\n","5           5.4          3.9           1.7          0.4\n","6           4.6          3.4           1.4          0.3\n","7           5.0          3.4           1.5          0.2"]},"execution_count":339,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","iris = iris.dropna(how='any')\n","iris.head()"]},{"cell_type":"markdown","metadata":{"id":"1E6EE1E034B442828989212B61361C86","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["### 步骤11 重新设置索引"]},{"cell_type":"code","execution_count":340,"metadata":{"collapsed":false,"id":"57DE9B3C6A9B42AC8384B0F0D501B02D","jupyter":{},"scrolled":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>sepal_length</th>\n","      <th>sepal_width</th>\n","      <th>petal_length</th>\n","      <th>petal_width</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>4.6</td>\n","      <td>3.1</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>5.0</td>\n","      <td>3.6</td>\n","      <td>1.4</td>\n","      <td>0.2</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>5.4</td>\n","      <td>3.9</td>\n","      <td>1.7</td>\n","      <td>0.4</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>4.6</td>\n","      <td>3.4</td>\n","      <td>1.4</td>\n","      <td>0.3</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>5.0</td>\n","      <td>3.4</td>\n","      <td>1.5</td>\n","      <td>0.2</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   sepal_length  sepal_width  petal_length  petal_width\n","0           4.6          3.1           1.5          0.2\n","1           5.0          3.6           1.4          0.2\n","2           5.4          3.9           1.7          0.4\n","3           4.6          3.4           1.4          0.3\n","4           5.0          3.4           1.5          0.2"]},"execution_count":340,"metadata":{},"output_type":"execute_result"}],"source":["# 运行以下代码\n","iris = iris.reset_index(drop = True)\n","iris.head()"]},{"cell_type":"markdown","metadata":{"id":"7CA8C9034FCE4018AE5E18CA6C9EF9B6","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["[返回练习题索引](#练习题索引)"]},{"cell_type":"markdown","metadata":{"id":"CBE9BD23998846BDA38F096FE818EFDD","jupyter":{},"mdEditEnable":false,"slideshow":{"slide_type":"slide"},"tags":[],"trusted":true},"source":["# 结语\n","恭喜你已经完成了这10套题目的练习✿✿ヽ(°▽°)ノ✿\n","**欢迎查看并Fork和鲸社区的 [镇站之宝](https://www.heywhale.com/mw/project/5e72e367c59d610036225bc0)获取更多学习内容**\n","**更多开源数据、分析项目、实战练习尽在[和鲸社区](heywhale.com)**\n"]}],"metadata":{"hide_input":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.4"},"toc":{"nav_menu":{},"number_sections":false,"sideBar":false,"skip_h1_title":false,"toc_cell":false,"toc_position":{"height":"537px","left":"1px","right":"20px","top":"106px","width":"234px"},"toc_section_display":"block","toc_window_display":false}},"nbformat":4,"nbformat_minor":2}
